
cd "" // set your working directory here

*********************************************************************************************************
*********************************************************************************************************
*********************************************************************************************************
*********************************************************************************************************
*********************************************************************************************************
****************************************** Placebo-lag DVs (Figure A4) **********************************
*********************************************************************************************************
*********************************************************************************************************
*********************************************************************************************************
*********************************************************************************************************
*********************************************************************************************************

use "Shooting Distance Date Reshape 2006-2014_full.dta", clear

sort fips year
gen dem_two_party_lag = dem_two_party[_n-1] if fips==fips[_n-1] & year > year[_n-1] 
gen turnout_pop_lag = dem_two_party[_n-1] if fips==fips[_n-1] & year > year[_n-1] 

gen year2=year*year

****** DEMOCRATIC VOTE SHARE (LAGGED)
reghdfe dem_two_party_lag any_shooting_in_county_year, absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year using "covariate_balance_results_updated.dta", detail(all) addlabel(treatment, any shooting, outcome, Lag Democratic Vote Share, model, two way fe, controls, none, model_num, 1) replace 

reghdfe dem_two_party_lag any_shooting_in_county_year rep_unopposed unopposed, absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year using "covariate_balance_results_updated.dta", detail(all) addlabel(treatment, any shooting, outcome, Lag Democratic Vote Share, model, two way fe, controls, unopposed, model_num, 2) append 

reghdfe dem_two_party_lag any_shooting_in_county_year rep_unopposed unopposed, absorb( fips year  c.year#i.fips) cluster(fips)
regsave any_shooting_in_county_year using "covariate_balance_results_updated.dta", detail(all) addlabel(treatment, any shooting, outcome, Lag Democratic Vote Share, model, linear time trend, controls, unopposed, model_num, 3) append 

reghdfe dem_two_party_lag any_shooting_in_county_year rep_unopposed unopposed, absorb( fips year  c.year#i.fips c.year2#i.fips) cluster(fips)
regsave any_shooting_in_county_year using "covariate_balance_results_updated.dta", detail(all) addlabel(treatment, any shooting, outcome, Lag Democratic Vote Share, model, quadratic time trend, controls, unopposed, model_num, 4) append 

****** TURNOUT (LAGGED)
reghdfe turnout_pop_lag any_shooting_in_county_year, absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year using "covariate_balance_results_updated.dta", detail(all) addlabel(treatment, any shooting, outcome, Lag Turnout, model, two way fe, controls, none, model_num, 1) append 

reghdfe turnout_pop_lag any_shooting_in_county_year rep_unopposed unopposed, absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year using "covariate_balance_results_updated.dta", detail(all) addlabel(treatment, any shooting, outcome, Lag Turnout, model, two way fe, controls, unopposed, model_num, 2) append 

reghdfe turnout_pop_lag any_shooting_in_county_year rep_unopposed unopposed, absorb( fips year  c.year#i.fips) cluster(fips)
regsave any_shooting_in_county_year using "covariate_balance_results_updated.dta", detail(all) addlabel(treatment, any shooting, outcome, Lag Turnout, model, linear time trend, controls, unopposed, model_num, 3) append 

reghdfe turnout_pop_lag any_shooting_in_county_year rep_unopposed unopposed, absorb( fips year  c.year#i.fips c.year2#i.fips) cluster(fips)
regsave any_shooting_in_county_year using "covariate_balance_results_updated.dta", detail(all) addlabel(treatment, any shooting, outcome, Lag Turnout, model, quadratic time trend, controls, unopposed, model_num, 4) append 

use "covariate_balance_results_updated.dta", clear

gen t_stat=coef/stderr
gen significant=1 if t_stat>1.96 | t_stat<-1.96
replace significant=0 if t_stat<1.96 & t_stat>-1.96

tab significant

saveold "covariate_balance_results_updated_cleaned.dta", replace version(12)



*********************************************************************************************************
*********************************************************************************************************
*********************************************************************************************************
*********************************************************************************************************
*********************************************************************************************************
****************************************** Effect on Democratic Vote Share (Fig 3) **********************
*********************************************************************************************************
*********************************************************************************************************
*********************************************************************************************************
*********************************************************************************************************
*********************************************************************************************************

use "Shooting Distance Date Reshape 2006-2014_full.dta", clear

gen year2=year*year

gen differece =dem_perc - rep_perc

sum differece
sum differece if differece<.0010929 & differece>-.0010929
disp 26 / 15420


*************** ALL SHOOTINGS (0/1)

** All Shootings No Controls Two Way Fixed Effects
reghdfe dem_two_party any_shooting_in_county_year , absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year using "election_outcomes_results_updated.dta", detail(all) addlabel(treatment, any shooting, outcome, Democratic Vote Share, model, two way fe, controls, none, model_num, 1) replace 

** All Shootings Controlling for Dem/Rep Unopposed Races Two Way Fixed Effects
reghdfe dem_two_party any_shooting_in_county_year rep_unopposed unopposed, absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year using "election_outcomes_results_updated.dta", detail(all) addlabel(treatment, any shooting, outcome, Democratic Vote Share, model, two way fe, controls, unopposed, model_num, 2) append 

** All Shootings, Two Way Fixed Effects + Linear Trends
reghdfe dem_two_party any_shooting_in_county_year  rep_unopposed unopposed , absorb( fips year c.year#i.fips) cluster(fips)
regsave any_shooting_in_county_year using "election_outcomes_results_updated.dta", detail(all) addlabel(treatment, any shooting, outcome, Democratic Vote Share, model, linear time trend, controls, unopposed, model_num, 3) append 

** All Shootings, Two Way Fixed Effects + Quadratic Trends
reghdfe dem_two_party any_shooting_in_county_year   rep_unopposed unopposed, absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave any_shooting_in_county_year using "election_outcomes_results_updated.dta", detail(all) addlabel(treatment, any shooting, outcome, Democratic Vote Share, model, quadratic time trend, controls, unopposed, model_num, 4) append 

************** BIG SHOOTINGS (0/1)

gen deaths_and_injuries=Injuries+Deaths

gen any_shooting_in_county_year_big=any_shooting_in_county_year
replace any_shooting_in_county_year_big=. if deaths_and_injuries<4 & deaths_and_injuries>0

** Big Shootings No Controls Two Way Fixed Effects
reghdfe dem_two_party any_shooting_in_county_year_big , absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year_big using "election_outcomes_results_updated.dta", detail(all) addlabel(treatment, any big shooting, outcome, Democratic Vote Share, model, two way fe, controls, none, model_num, 1) append 

** Big Shootings Controlling for Dem/Rep Unopposed Races Two Way Fixed Effects
reghdfe dem_two_party any_shooting_in_county_year_big rep_unopposed unopposed, absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year_big using "election_outcomes_results_updated.dta", detail(all) addlabel(treatment, any big shooting, outcome, Democratic Vote Share, model, two way fe, controls, unopposed, model_num, 2) append 

** Big Shootings, Two Way Fixed Effects + Linear Trends
reghdfe dem_two_party any_shooting_in_county_year_big  rep_unopposed unopposed , absorb( fips year c.year#i.fips) cluster(fips)
regsave any_shooting_in_county_year_big using "election_outcomes_results_updated.dta", detail(all) addlabel(treatment, any big shooting, outcome, Democratic Vote Share, model, linear time trend, controls, unopposed, model_num, 3) append 

** Big Shootings, Two Way Fixed Effects + Quadratic Trends
reghdfe dem_two_party any_shooting_in_county_year_big  rep_unopposed unopposed , absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave any_shooting_in_county_year_big using "election_outcomes_results_updated.dta", detail(all) addlabel(treatment, any big shooting, outcome, Democratic Vote Share, model, quadratic time trend, controls, unopposed, model_num, 4) append 


************** DEATHS + INJURIES (continuous)

egen deaths_and_injuries_std=std(deaths_and_injuries), mean(0) std(1)
egen deaths_std=std(Deaths), mean(0) std(1)
egen injuries_std=std(Injuries), mean(0) std(1)

** No Controls Two Way Fixed Effects
reghdfe dem_two_party deaths_and_injuries_std , absorb( fips year) cluster(fips)
regsave deaths_and_injuries_std using "election_outcomes_results_updated.dta", detail(all) addlabel(treatment, deaths and injuries standardize, outcome, Democratic Vote Share, model, two way fe, controls, none, model_num, 1) append 

** Controlling for Dem/Rep Unopposed Races Two Way Fixed Effects
reghdfe dem_two_party deaths_and_injuries_std rep_unopposed unopposed, absorb( fips year) cluster(fips)
regsave deaths_and_injuries_std using "election_outcomes_results_updated.dta", detail(all) addlabel(treatment, deaths and injuries standardize, outcome, Democratic Vote Share, model, two way fe, controls, unopposed, model_num, 2) append 

** Two Way Fixed Effects + Linear Trends
reghdfe dem_two_party deaths_and_injuries_std  rep_unopposed unopposed , absorb( fips year c.year#i.fips) cluster(fips)
regsave deaths_and_injuries_std using "election_outcomes_results_updated.dta", detail(all) addlabel(treatment, deaths and injuries standardize, outcome, Democratic Vote Share, model, linear time trend, controls, unopposed, model_num, 3) append 

** Two Way Fixed Effects + Quadratic Trends
reghdfe dem_two_party deaths_and_injuries_std  rep_unopposed unopposed , absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave deaths_and_injuries_std using "election_outcomes_results_updated.dta", detail(all) addlabel(treatment, deaths and injuries standardize, outcome, Democratic Vote Share, model, quadratic time trend, controls, unopposed, model_num, 4) append 


************** CLOSE BY TREATED (ALL YEAR)

egen min_dist_shoot_year=rowmin(distance_11closest_eday distance_10closest_eday distance_9closest_eday distance_8closest_eday distance_7closest_eday distance_6closest_eday distance_5closest_eday distance_4closest_eday distance_3closest_eday distance_2closest_eday distance_closest_eday distance_33closest_eday distance_32closest_eday distance_31closest_eday distance_30closest_eday distance_29closest_eday distance_28closest_eday distance_27closest_eday distance_26closest_eday distance_25closest_eday distance_24closest_eday distance_23closest_eday distance_22closest_eday distance_21closest_eday distance_20closest_eday distance_19closest_eday distance_18closest_eday distance_17closest_eday distance_16closest_eday distance_15closest_eday distance_14closest_eday distance_13closest_eday distance_12closest_eday)

gen reverse_min_distance_year=-min_dist_shoot_year
egen reverse_min_distance_year_s=std(reverse_min_distance_year), mean(0) std(1)

** No Controls Two Way Fixed Effects
reghdfe dem_two_party reverse_min_distance_year_s , absorb( fips year) cluster(fips)
regsave reverse_min_distance_year_s using "election_outcomes_results_updated.dta", detail(all) addlabel(treatment, close by shooting, outcome, Democratic Vote Share, model, two way fe, controls, none, model_num, 1) append 

** Controlling for Dem/Rep Unopposed Races Two Way Fixed Effects
reghdfe dem_two_party reverse_min_distance_year_s rep_unopposed unopposed, absorb( fips year) cluster(fips)
regsave reverse_min_distance_year_s using "election_outcomes_results_updated.dta", detail(all) addlabel(treatment, close by shooting, outcome, Democratic Vote Share, model, two way fe, controls, unopposed, model_num, 2) append 

** Two Way Fixed Effects + Linear Trends
sum distance_closest_eday, d // 25th percentile
reghdfe dem_two_party reverse_min_distance_year_s  rep_unopposed unopposed , absorb( fips year c.year#i.fips) cluster(fips)
regsave reverse_min_distance_year_s using "election_outcomes_results_updated.dta", detail(all) addlabel(treatment, close by shooting, outcome, Democratic Vote Share, model, linear time trend, controls, unopposed, model_num, 3) append 

** Two Way Fixed Effects + Quadratic Trends
reghdfe dem_two_party reverse_min_distance_year_s  rep_unopposed unopposed , absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave reverse_min_distance_year_s using "election_outcomes_results_updated.dta", detail(all) addlabel(treatment, close by shooting, outcome, Democratic Vote Share, model, quadratic time trend, controls, unopposed, model_num, 4) append 

use "election_outcomes_results_updated.dta", clear

gen t_stat=coef/stderr
gen significant=1 if t_stat>1.96 | t_stat<-1.96
replace significant=0 if t_stat<1.96 & t_stat>-1.96

tab significant

sum coef, d
kdensity coef

replace var="Distance to Closest Shooting (Std.)" if var=="reverse_min_distance_year_s"
replace var="Deaths and Injuries (Std.)" if var=="deaths_and_injuries_std"
replace var="Any School Shooting (Only Mass)" if var=="any_shooting_in_county_year_big"
replace var="Any School Shooting" if var=="any_shooting_in_county_year"

saveold "election_outcomes_results_updated_cleaned.dta", version(12) replace


*********************************************************************************************************
*********************************************************************************************************
*********************************************************************************************************
*********************************************************************************************************
*********************************************************************************************************
****************************************** Effect on Turnout (Fig 3) ************************************
*********************************************************************************************************
*********************************************************************************************************
*********************************************************************************************************
*********************************************************************************************************
*********************************************************************************************************

use "Shooting Distance Date Reshape 2006-2014_full.dta", clear

gen year2=year*year

*************** ALL SHOOTINGS (0/1)

** All Shootings No Controls Two Way Fixed Effects
reghdfe turnout_pop any_shooting_in_county_year , absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year using "turnout_results_updated.dta", detail(all) addlabel(treatment, any shooting, outcome, Voter Turnout, model, two way fe, controls, none, model_num, 1) replace 

** All Shootings Controlling for Dem/Rep Unopposed Races Two Way Fixed Effects
reghdfe turnout_pop any_shooting_in_county_year rep_unopposed unopposed, absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year using "turnout_results_updated.dta", detail(all) addlabel(treatment, any shooting, outcome, Voter Turnout, model, two way fe, controls, unopposed, model_num, 2) append 

** All Shootings, Two Way Fixed Effects + Linear Trends
reghdfe turnout_pop any_shooting_in_county_year  rep_unopposed unopposed , absorb( fips year c.year#i.fips) cluster(fips)
regsave any_shooting_in_county_year using "turnout_results_updated.dta", detail(all) addlabel(treatment, any shooting, outcome, Voter Turnout, model, linear time trend, controls, unopposed, model_num, 3) append 

** All Shootings, Two Way Fixed Effects + Quadratic Trends
reghdfe turnout_pop any_shooting_in_county_year   rep_unopposed unopposed, absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave any_shooting_in_county_year using "turnout_results_updated.dta", detail(all) addlabel(treatment, any shooting, outcome, Voter Turnout, model, quadratic time trend, controls, unopposed, model_num, 4) append 

************** BIG SHOOTINGS (0/1)

gen deaths_and_injuries=Injuries+Deaths

gen any_shooting_in_county_year_big=any_shooting_in_county_year
replace any_shooting_in_county_year_big=. if deaths_and_injuries<4 & deaths_and_injuries>0

** Big Shootings No Controls Two Way Fixed Effects
reghdfe turnout_pop any_shooting_in_county_year_big , absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year_big using "turnout_results_updated.dta", detail(all) addlabel(treatment, any big shooting, outcome, Voter Turnout, model, two way fe, controls, none, model_num, 1) append 

** Big Shootings Controlling for Dem/Rep Unopposed Races Two Way Fixed Effects
reghdfe turnout_pop any_shooting_in_county_year_big rep_unopposed unopposed, absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year_big using "turnout_results_updated.dta", detail(all) addlabel(treatment, any big shooting, outcome, Voter Turnout, model, two way fe, controls, unopposed, model_num, 2) append 

** Big Shootings, Two Way Fixed Effects + Linear Trends
reghdfe turnout_pop any_shooting_in_county_year_big  rep_unopposed unopposed , absorb( fips year c.year#i.fips) cluster(fips)
regsave any_shooting_in_county_year_big using "turnout_results_updated.dta", detail(all) addlabel(treatment, any big shooting, outcome, Voter Turnout, model, linear time trend, controls, unopposed, model_num, 3) append 

** Big Shootings, Two Way Fixed Effects + Quadratic Trends
reghdfe turnout_pop any_shooting_in_county_year_big  rep_unopposed unopposed , absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave any_shooting_in_county_year_big using "turnout_results_updated.dta", detail(all) addlabel(treatment, any big shooting, outcome, Voter Turnout, model, quadratic time trend, controls, unopposed, model_num, 4) append 


************** DEATHS + INJURIES (continuous)

egen deaths_and_injuries_std=std(deaths_and_injuries), mean(0) std(1)
egen deaths_std=std(Deaths), mean(0) std(1)
egen injuries_std=std(Injuries), mean(0) std(1)

** No Controls Two Way Fixed Effects
reghdfe turnout_pop deaths_and_injuries_std , absorb( fips year) cluster(fips)
regsave deaths_and_injuries_std using "turnout_results_updated.dta", detail(all) addlabel(treatment, deaths and injuries standardize, outcome, Voter Turnout, model, two way fe, controls, none, model_num, 1) append 

** Controlling for Dem/Rep Unopposed Races Two Way Fixed Effects
reghdfe turnout_pop deaths_and_injuries_std rep_unopposed unopposed, absorb( fips year) cluster(fips)
regsave deaths_and_injuries_std using "turnout_results_updated.dta", detail(all) addlabel(treatment, deaths and injuries standardize, outcome, Voter Turnout, model, two way fe, controls, unopposed, model_num, 2) append 

** Two Way Fixed Effects + Linear Trends
reghdfe turnout_pop deaths_and_injuries_std  rep_unopposed unopposed , absorb( fips year c.year#i.fips) cluster(fips)
regsave deaths_and_injuries_std using "turnout_results_updated.dta", detail(all) addlabel(treatment, deaths and injuries standardize, outcome, Voter Turnout, model, linear time trend, controls, unopposed, model_num, 3) append 

** Two Way Fixed Effects + Quadratic Trends
reghdfe turnout_pop deaths_and_injuries_std  rep_unopposed unopposed , absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave deaths_and_injuries_std using "turnout_results_updated.dta", detail(all) addlabel(treatment, deaths and injuries standardize, outcome, Voter Turnout, model, quadratic time trend, controls, unopposed, model_num, 4) append 

************** CLOSE BY TREATED (ALL YEAR)

egen min_dist_shoot_year=rowmin(distance_11closest_eday distance_10closest_eday distance_9closest_eday distance_8closest_eday distance_7closest_eday distance_6closest_eday distance_5closest_eday distance_4closest_eday distance_3closest_eday distance_2closest_eday distance_closest_eday distance_33closest_eday distance_32closest_eday distance_31closest_eday distance_30closest_eday distance_29closest_eday distance_28closest_eday distance_27closest_eday distance_26closest_eday distance_25closest_eday distance_24closest_eday distance_23closest_eday distance_22closest_eday distance_21closest_eday distance_20closest_eday distance_19closest_eday distance_18closest_eday distance_17closest_eday distance_16closest_eday distance_15closest_eday distance_14closest_eday distance_13closest_eday distance_12closest_eday)

gen reverse_min_distance_year=-min_dist_shoot_year
egen reverse_min_distance_year_s=std(reverse_min_distance_year), mean(0) std(1)

** No Controls Two Way Fixed Effects
reghdfe turnout_pop reverse_min_distance_year_s , absorb( fips year) cluster(fips)
regsave reverse_min_distance_year_s using "turnout_results_updated.dta", detail(all) addlabel(treatment, close by shooting, outcome, Voter Turnout, model, two way fe, controls, none, model_num, 1) append 

** Controlling for Dem/Rep Unopposed Races Two Way Fixed Effects
reghdfe turnout_pop reverse_min_distance_year_s rep_unopposed unopposed, absorb( fips year) cluster(fips)
regsave reverse_min_distance_year_s using "turnout_results_updated.dta", detail(all) addlabel(treatment, close by shooting, outcome, Voter Turnout, model, two way fe, controls, unopposed, model_num, 2) append 

** Two Way Fixed Effects + Linear Trends
reghdfe turnout_pop reverse_min_distance_year_s  rep_unopposed unopposed , absorb( fips year c.year#i.fips) cluster(fips)
regsave reverse_min_distance_year_s using "turnout_results_updated.dta", detail(all) addlabel(treatment, close by shooting, outcome, Voter Turnout, model, linear time trend, controls, unopposed, model_num, 3) append 

** Two Way Fixed Effects + Quadratic Trends
reghdfe turnout_pop reverse_min_distance_year_s  rep_unopposed unopposed , absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave reverse_min_distance_year_s using "turnout_results_updated.dta", detail(all) addlabel(treatment, close by shooting, outcome, Voter Turnout, model, quadratic time trend, controls, unopposed, model_num, 4) append 

use "turnout_results_updated.dta", clear

gen t_stat=coef/stderr
gen significant=1 if t_stat>1.96 | t_stat<-1.96
replace significant=0 if t_stat<1.96 & t_stat>-1.96

tab significant

sum coef, d
kdensity coef

replace var="Distance to Closest Shooting (Std.)" if var=="reverse_min_distance_year_s"
replace var="Deaths and Injuries (Std.)" if var=="deaths_and_injuries_std"
replace var="Any School Shooting (Only Mass)" if var=="any_shooting_in_county_year_big"
replace var="Any School Shooting" if var=="any_shooting_in_county_year"

saveold "turnout_results_updated_cleaned.dta", version(12) replace


*********************************************************************************************************
*********************************************************************************************************
*********************************************************************************************************
*********************************************************************************************************
*********************************************************************************************************
****************************************** ELECTION OUTCOMES--APPENDIX **********************************
*********************************************************************************************************
*********************************************************************************************************
*********************************************************************************************************
*********************************************************************************************************
*********************************************************************************************************

*****************************************************************************************************************************
*********************** VOTE SHARE: Just Comparing to Counties Close by in the Comparison Group (Figure A5) *****************
*****************************************************************************************************************************

use "Shooting Distance Date Reshape 2006-2014_full.dta", clear

gen year2=year*year

gen deaths_and_injuries=Injuries+Deaths
egen deaths_and_injuries_std=std(deaths_and_injuries), mean(0) std(1)
egen deaths_std=std(Deaths), mean(0) std(1)
egen injuries_std=std(Injuries), mean(0) std(1)

gen any_shooting_in_county_year_big=any_shooting_in_county_year
replace any_shooting_in_county_year_big=. if deaths_and_injuries<4 & deaths_and_injuries>0

egen min_dist_shoot_year=rowmin(distance_11closest_eday distance_10closest_eday distance_9closest_eday distance_8closest_eday distance_7closest_eday distance_6closest_eday distance_5closest_eday distance_4closest_eday distance_3closest_eday distance_2closest_eday distance_closest_eday distance_33closest_eday distance_32closest_eday distance_31closest_eday distance_30closest_eday distance_29closest_eday distance_28closest_eday distance_27closest_eday distance_26closest_eday distance_25closest_eday distance_24closest_eday distance_23closest_eday distance_22closest_eday distance_21closest_eday distance_20closest_eday distance_19closest_eday distance_18closest_eday distance_17closest_eday distance_16closest_eday distance_15closest_eday distance_14closest_eday distance_13closest_eday distance_12closest_eday)

gen reverse_min_distance_year=-min_dist_shoot_year
egen reverse_min_distance_year_s=std(reverse_min_distance_year), mean(0) std(1)

sum min_dist_shoot_year, d // 50th percentile = 235.1093

*************** ALL SHOOTINGS (0/1)

reghdfe dem_two_party any_shooting_in_county_year if  min_dist_shoot_year<  235.1093    , absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year  using "election_outcomes_results_closest_controls.dta", detail(all) addlabel(outcome, Democratic Vote Share, treatment, Any School Shooting, model, two way, model_num, 1) replace 

reghdfe dem_two_party any_shooting_in_county_year rep_unopposed unopposed if min_dist_shoot_year<  235.1093   , absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year using "election_outcomes_results_closest_controls.dta", detail(all) addlabel(outcome, Democratic Vote Share, treatment, Any School Shooting, model, two way with unopposed, model_num, 2) append 

reghdfe dem_two_party any_shooting_in_county_year rep_unopposed unopposed if min_dist_shoot_year<  235.1093  , absorb( fips year c.year#i.fips) cluster(fips)
regsave any_shooting_in_county_year using "election_outcomes_results_closest_controls.dta", detail(all) addlabel(outcome, Democratic Vote Share,  treatment, Any School Shooting, model, linear trend, model_num, 3) append

reghdfe dem_two_party any_shooting_in_county_year rep_unopposed unopposed if min_dist_shoot_year<  235.1093  , absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave any_shooting_in_county_year using "election_outcomes_results_closest_controls.dta", detail(all) addlabel(outcome, Democratic Vote Share,  treatment, Any School Shooting, model, quadratic trend, model_num, 4) append

********* BIG SHOOTINGS (0/1)

** [CLOSEST TO WHAT YOUSAF DOES]
reghdfe dem_two_party any_shooting_in_county_year_big if min_dist_shoot_year<  235.1093 , absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year_big using "election_outcomes_results_closest_controls.dta", detail(all) addlabel(outcome, Democratic Vote Share,  treatment, Any School Shooting (Only Mass), model, two way, model_num, 1) append 

** [BUT GOES AWAY WITH UNCONTESTED]
reghdfe dem_two_party any_shooting_in_county_year_big rep_unopposed unopposed if min_dist_shoot_year<  235.1093  , absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year_big using "election_outcomes_results_closest_controls.dta", detail(all) addlabel(outcome, Democratic Vote Share,  treatment, Any School Shooting (Only Mass), model, two way with unopposed, model_num, 2) append 

reghdfe dem_two_party any_shooting_in_county_year_big rep_unopposed unopposed if min_dist_shoot_year<  235.1093  , absorb( fips year c.year#i.fips) cluster(fips)
regsave any_shooting_in_county_year_big using "election_outcomes_results_closest_controls.dta", detail(all) addlabel(outcome, Democratic Vote Share,  treatment, Any School Shooting (Only Mass), model, linear trend, model_num, 3) append

reghdfe dem_two_party any_shooting_in_county_year_big rep_unopposed unopposed if min_dist_shoot_year<  235.1093  , absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave any_shooting_in_county_year_big using "election_outcomes_results_closest_controls.dta", detail(all) addlabel(outcome, Democratic Vote Share,  treatment, Any School Shooting (Only Mass), model, quadratic trend, model_num, 4) append

******** DEATHS AND INJURIES
reghdfe dem_two_party deaths_and_injuries_std if min_dist_shoot_year<  235.1093  , absorb( fips year) cluster(fips)
regsave deaths_and_injuries_std using "election_outcomes_results_closest_controls.dta", detail(all) addlabel(outcome, Democratic Vote Share, treatment, Deaths and Injuries (Std.), model, two way, model_num, 1) append 

reghdfe dem_two_party deaths_and_injuries_std rep_unopposed unopposed if min_dist_shoot_year<  235.1093  , absorb( fips year) cluster(fips)
regsave deaths_and_injuries_std using "election_outcomes_results_closest_controls.dta", detail(all) addlabel(outcome, Democratic Vote Share, treatment, Deaths and Injuries (Std.), model, two way with unopposed, model_num, 2) append 

reghdfe dem_two_party deaths_and_injuries_std rep_unopposed unopposed if min_dist_shoot_year<  235.1093  , absorb( fips year c.year#i.fips) cluster(fips)
regsave deaths_and_injuries_std using "election_outcomes_results_closest_controls.dta", detail(all) addlabel(outcome, Democratic Vote Share,  treatment, Deaths and Injuries (Std.), model, linear trend, model_num, 3) append

reghdfe dem_two_party deaths_and_injuries_std rep_unopposed unopposed if min_dist_shoot_year<  235.1093  , absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave deaths_and_injuries_std using "election_outcomes_results_closest_controls.dta", detail(all) addlabel(outcome, Democratic Vote Share,  treatment, Deaths and Injuries (Std.), model, quadratic trend, model_num, 4) append

******** DISTANCE TO SHOOTING

reghdfe dem_two_party reverse_min_distance_year_s if min_dist_shoot_year< 235.1093   , absorb( fips year) cluster(fips)
regsave reverse_min_distance_year_s using "election_outcomes_results_closest_controls.dta", detail(all) addlabel(outcome, Democratic Vote Share, treatment, Distance to Closest Shooting (Std.), model, two way, model_num, 1) append 

reghdfe dem_two_party reverse_min_distance_year_s rep_unopposed unopposed if min_dist_shoot_year< 235.1093   , absorb( fips year) cluster(fips)
regsave reverse_min_distance_year_s using "election_outcomes_results_closest_controls.dta", detail(all) addlabel(outcome, Democratic Vote Share, treatment, Distance to Closest Shooting (Std.), model, two way with unopposed, model_num, 2) append 

reghdfe dem_two_party reverse_min_distance_year_s rep_unopposed unopposed if min_dist_shoot_year<  235.1093  , absorb( fips year c.year#i.fips) cluster(fips)
regsave reverse_min_distance_year_s using "election_outcomes_results_closest_controls.dta", detail(all) addlabel(outcome, Democratic Vote Share,  treatment, Distance to Closest Shooting (Std.), model, linear trend, model_num, 3) append

reghdfe dem_two_party reverse_min_distance_year_s rep_unopposed unopposed if min_dist_shoot_year<  235.1093  , absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave reverse_min_distance_year_s using "election_outcomes_results_closest_controls.dta", detail(all) addlabel(outcome, Democratic Vote Share,  treatment, Distance to Closest Shooting (Std.), model, quadratic trend, model_num, 4) append

use "election_outcomes_results_closest_controls.dta", clear

gen t_stat=coef/stderr
gen significant=1 if t_stat>1.96 | t_stat<-1.96
replace significant=0 if t_stat<1.96 & t_stat>-1.96

tab significant

saveold "election_outcomes_results_closest_controls_cleaned.dta", version(12) replace


*****************************************************************************************************************************
**************************** VOTER TURNOUT: Just Comparing to Counties Close by in the Comparison Group (Figure A6) *********
*****************************************************************************************************************************

use "Shooting Distance Date Reshape 2006-2014_full.dta", clear

gen year2=year*year

gen deaths_and_injuries=Injuries+Deaths
egen deaths_and_injuries_std=std(deaths_and_injuries), mean(0) std(1)
egen deaths_std=std(Deaths), mean(0) std(1)
egen injuries_std=std(Injuries), mean(0) std(1)

gen any_shooting_in_county_year_big=any_shooting_in_county_year
replace any_shooting_in_county_year_big=. if deaths_and_injuries<4 & deaths_and_injuries>0

egen min_dist_shoot_year=rowmin(distance_11closest_eday distance_10closest_eday distance_9closest_eday distance_8closest_eday distance_7closest_eday distance_6closest_eday distance_5closest_eday distance_4closest_eday distance_3closest_eday distance_2closest_eday distance_closest_eday distance_33closest_eday distance_32closest_eday distance_31closest_eday distance_30closest_eday distance_29closest_eday distance_28closest_eday distance_27closest_eday distance_26closest_eday distance_25closest_eday distance_24closest_eday distance_23closest_eday distance_22closest_eday distance_21closest_eday distance_20closest_eday distance_19closest_eday distance_18closest_eday distance_17closest_eday distance_16closest_eday distance_15closest_eday distance_14closest_eday distance_13closest_eday distance_12closest_eday)

gen reverse_min_distance_year=-min_dist_shoot_year
egen reverse_min_distance_year_s=std(reverse_min_distance_year), mean(0) std(1)

sum min_dist_shoot_year, d // 50th percentile = 235.1093

*************** ALL SHOOTINGS (0/1)

reghdfe turnout_pop any_shooting_in_county_year if  min_dist_shoot_year<  235.1093    , absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year  using "voter_turnout_results_closest_controls.dta", detail(all) addlabel(outcome, Voter Turnout, treatment, Any School Shooting, model, two way, model_num, 1) replace 

reghdfe turnout_pop any_shooting_in_county_year rep_unopposed unopposed if min_dist_shoot_year<  235.1093   , absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year using "voter_turnout_results_closest_controls.dta", detail(all) addlabel(outcome, Voter Turnout, treatment, Any School Shooting, model, two way with unopposed, model_num, 2) append 

reghdfe turnout_pop any_shooting_in_county_year rep_unopposed unopposed if min_dist_shoot_year<  235.1093  , absorb( fips year c.year#i.fips) cluster(fips)
regsave any_shooting_in_county_year using "voter_turnout_results_closest_controls.dta", detail(all) addlabel(outcome, Voter Turnout,  treatment, Any School Shooting, model, linear trend, model_num, 3) append

reghdfe turnout_pop any_shooting_in_county_year rep_unopposed unopposed if min_dist_shoot_year<  235.1093  , absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave any_shooting_in_county_year using "voter_turnout_results_closest_controls.dta", detail(all) addlabel(outcome, Voter Turnout,  treatment, Any School Shooting, model, quadratic trend, model_num, 4) append

********* BIG SHOOTINGS (0/1)

** [CLOSEST TO WHAT YOUSAF DOES]
reghdfe turnout_pop any_shooting_in_county_year_big if min_dist_shoot_year<  235.1093 , absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year_big using "voter_turnout_results_closest_controls.dta", detail(all) addlabel(outcome, Voter Turnout,  treatment, Any School Shooting (Only Mass), model, two way, model_num, 1) append 

** [BUT GOES AWAY WITH UNCONTESTED]
reghdfe turnout_pop any_shooting_in_county_year_big rep_unopposed unopposed if min_dist_shoot_year<  235.1093  , absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year_big using "voter_turnout_results_closest_controls.dta", detail(all) addlabel(outcome, Voter Turnout,  treatment, Any School Shooting (Only Mass), model, two way with unopposed, model_num, 2) append 

reghdfe turnout_pop any_shooting_in_county_year_big rep_unopposed unopposed if min_dist_shoot_year<  235.1093  , absorb( fips year c.year#i.fips) cluster(fips)
regsave any_shooting_in_county_year_big using "voter_turnout_results_closest_controls.dta", detail(all) addlabel(outcome, Voter Turnout,  treatment, Any School Shooting (Only Mass), model, linear trend, model_num, 3) append

reghdfe turnout_pop any_shooting_in_county_year_big rep_unopposed unopposed if min_dist_shoot_year<  235.1093  , absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave any_shooting_in_county_year_big using "voter_turnout_results_closest_controls.dta", detail(all) addlabel(outcome, Voter Turnout,  treatment, Any School Shooting (Only Mass), model, quadratic trend, model_num, 4) append

******** DEATHS AND INJURIES
reghdfe turnout_pop deaths_and_injuries_std if min_dist_shoot_year<  235.1093  , absorb( fips year) cluster(fips)
regsave deaths_and_injuries_std using "voter_turnout_results_closest_controls.dta", detail(all) addlabel(outcome, Voter Turnout, treatment, Deaths and Injuries (Std.), model, two way, model_num, 1) append 

reghdfe turnout_pop deaths_and_injuries_std rep_unopposed unopposed if min_dist_shoot_year<  235.1093  , absorb( fips year) cluster(fips)
regsave deaths_and_injuries_std using "voter_turnout_results_closest_controls.dta", detail(all) addlabel(outcome, Voter Turnout, treatment, Deaths and Injuries (Std.), model, two way with unopposed, model_num, 2) append 

reghdfe turnout_pop deaths_and_injuries_std rep_unopposed unopposed if min_dist_shoot_year<  235.1093  , absorb( fips year c.year#i.fips) cluster(fips)
regsave deaths_and_injuries_std using "voter_turnout_results_closest_controls.dta", detail(all) addlabel(outcome, Voter Turnout,  treatment, Deaths and Injuries (Std.), model, linear trend, model_num, 3) append

reghdfe turnout_pop deaths_and_injuries_std rep_unopposed unopposed if min_dist_shoot_year<  235.1093  , absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave deaths_and_injuries_std using "voter_turnout_results_closest_controls.dta", detail(all) addlabel(outcome, Voter Turnout,  treatment, Deaths and Injuries (Std.), model, quadratic trend, model_num, 4) append

******** DISTANCE TO SHOOTING

reghdfe turnout_pop reverse_min_distance_year_s if min_dist_shoot_year< 235.1093   , absorb( fips year) cluster(fips)
regsave reverse_min_distance_year_s using "voter_turnout_results_closest_controls.dta", detail(all) addlabel(outcome, Voter Turnout, treatment, Distance to Closest Shooting (Std.), model, two way, model_num, 1) append 

reghdfe turnout_pop reverse_min_distance_year_s rep_unopposed unopposed if min_dist_shoot_year< 235.1093   , absorb( fips year) cluster(fips)
regsave reverse_min_distance_year_s using "voter_turnout_results_closest_controls.dta", detail(all) addlabel(outcome, Voter Turnout, treatment, Distance to Closest Shooting (Std.), model, two way with unopposed, model_num, 2) append 

reghdfe turnout_pop reverse_min_distance_year_s rep_unopposed unopposed if min_dist_shoot_year<  235.1093  , absorb( fips year c.year#i.fips) cluster(fips)
regsave reverse_min_distance_year_s using "voter_turnout_results_closest_controls.dta", detail(all) addlabel(outcome, Voter Turnout,  treatment, Distance to Closest Shooting (Std.), model, linear trend, model_num, 3) append

reghdfe turnout_pop reverse_min_distance_year_s rep_unopposed unopposed if min_dist_shoot_year<  235.1093  , absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave reverse_min_distance_year_s using "voter_turnout_results_closest_controls.dta", detail(all) addlabel(outcome, Voter Turnout,  treatment, Distance to Closest Shooting (Std.), model, quadratic trend, model_num, 4) append

use "voter_turnout_results_closest_controls.dta", clear

gen t_stat=coef/stderr
gen significant=1 if t_stat>1.96 | t_stat<-1.96
replace significant=0 if t_stat<1.96 & t_stat>-1.96

tab significant

saveold "voter_turnout_results_closest_controls_cleaned.dta", version(12) replace

*****************************************************************************************************************************
********************************* Are races more likely to be uncontested because of shootings? (Fig A8-A10) ****************
*****************************************************************************************************************************

use "Shooting Distance Date Reshape 2006-2014_full.dta", clear

gen year2=year*year

gen deaths_and_injuries=Injuries+Deaths
egen deaths_and_injuries_std=std(deaths_and_injuries), mean(0) std(1)
egen deaths_std=std(Deaths), mean(0) std(1)
egen injuries_std=std(Injuries), mean(0) std(1)

gen any_shooting_in_county_year_big=any_shooting_in_county_year
replace any_shooting_in_county_year_big=. if deaths_and_injuries<4 & deaths_and_injuries>0

egen min_dist_shoot_year=rowmin(distance_11closest_eday distance_10closest_eday distance_9closest_eday distance_8closest_eday distance_7closest_eday distance_6closest_eday distance_5closest_eday distance_4closest_eday distance_3closest_eday distance_2closest_eday distance_closest_eday distance_33closest_eday distance_32closest_eday distance_31closest_eday distance_30closest_eday distance_29closest_eday distance_28closest_eday distance_27closest_eday distance_26closest_eday distance_25closest_eday distance_24closest_eday distance_23closest_eday distance_22closest_eday distance_21closest_eday distance_20closest_eday distance_19closest_eday distance_18closest_eday distance_17closest_eday distance_16closest_eday distance_15closest_eday distance_14closest_eday distance_13closest_eday distance_12closest_eday)

gen reverse_min_distance_year=-min_dist_shoot_year
egen reverse_min_distance_year_s=std(reverse_min_distance_year), mean(0) std(1)

*************** Any Shooting

*Model 1-two way
reghdfe rep_unopposed any_shooting_in_county_year    , absorb( fips year ) cluster(fips)
regsave any_shooting_in_county_year using "who_runs.dta", detail(all) addlabel(outcome, Republican Runs Unopposed, treatment, Any School Shooting, model, two way, model_num, 1) replace

reghdfe unopposed any_shooting_in_county_year    , absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year using "who_runs.dta", detail(all) addlabel(outcome, Democrat Runs Unopposed, treatment, Any School Shooting, model, two way, model_num, 1) append

reghdfe unopposed_either any_shooting_in_county_year    , absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year using "who_runs.dta", detail(all) addlabel(outcome, Either Party Runs Unopposed, treatment, Any School Shooting, model, two way, model_num, 1) append

*Model 2-linear trend
reghdfe rep_unopposed any_shooting_in_county_year    , absorb( fips year c.year#i.fips) cluster(fips)
regsave any_shooting_in_county_year using "who_runs.dta", detail(all) addlabel(outcome, Republican Runs Unopposed, treatment, Any School Shooting, model, linear trend, model_num, 2) append

reghdfe unopposed any_shooting_in_county_year    , absorb( fips year c.year#i.fips) cluster(fips)
regsave any_shooting_in_county_year using "who_runs.dta", detail(all) addlabel(outcome, Democrat Runs Unopposed, treatment, Any School Shooting, model, linear trend, model_num, 2) append

reghdfe unopposed_either any_shooting_in_county_year    , absorb( fips year c.year#i.fips) cluster(fips)
regsave any_shooting_in_county_year using "who_runs.dta", detail(all) addlabel(outcome, Either Party Runs Unopposed, treatment, Any School Shooting, model, linear trend, model_num, 2) append

*Model 3-quadratic trend
reghdfe rep_unopposed any_shooting_in_county_year    , absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave any_shooting_in_county_year using "who_runs.dta", detail(all) addlabel(outcome, Republican Runs Unopposed, treatment, Any School Shooting, model, quadratic trend, model_num, 3) append

reghdfe unopposed any_shooting_in_county_year    , absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave any_shooting_in_county_year using "who_runs.dta", detail(all) addlabel(outcome, Democrat Runs Unopposed, treatment, Any School Shooting, model, quadratic trend, model_num, 3) append

reghdfe unopposed_either any_shooting_in_county_year    , absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave any_shooting_in_county_year using "who_runs.dta", detail(all) addlabel(outcome, Either Party Runs Unopposed, treatment, Any School Shooting, model, quadratic trend, model_num, 3) append

*************** Any Shooting (Mass Only)

*Model 1-two way
reghdfe rep_unopposed any_shooting_in_county_year_big    , absorb( fips year ) cluster(fips)
regsave any_shooting_in_county_year_big using "who_runs.dta", detail(all) addlabel(outcome, Republican Runs Unopposed, treatment, Any School Shooting (Only Mass), model, two way, model_num, 1) append

reghdfe unopposed any_shooting_in_county_year_big    , absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year_big using "who_runs.dta", detail(all) addlabel(outcome, Democrat Runs Unopposed, treatment, Any School Shooting (Only Mass), model, two way, model_num, 1) append

reghdfe unopposed_either any_shooting_in_county_year_big    , absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year_big using "who_runs.dta", detail(all) addlabel(outcome, Either Party Runs Unopposed, treatment, Any School Shooting (Only Mass), model, two way, model_num, 1) append

*Model 2-linear trend
reghdfe rep_unopposed any_shooting_in_county_year_big    , absorb( fips year c.year#i.fips) cluster(fips)
regsave any_shooting_in_county_year_big using "who_runs.dta", detail(all) addlabel(outcome, Republican Runs Unopposed, treatment, Any School Shooting (Only Mass), model, linear trend, model_num, 2) append

reghdfe unopposed any_shooting_in_county_year_big    , absorb( fips year c.year#i.fips) cluster(fips)
regsave any_shooting_in_county_year_big using "who_runs.dta", detail(all) addlabel(outcome, Democrat Runs Unopposed, treatment, Any School Shooting (Only Mass), model, linear trend, model_num, 2) append

reghdfe unopposed_either any_shooting_in_county_year_big    , absorb( fips year c.year#i.fips) cluster(fips)
regsave any_shooting_in_county_year_big using "who_runs.dta", detail(all) addlabel(outcome, Either Party Runs Unopposed, treatment, Any School Shooting (Only Mass), model, linear trend, model_num, 2) append

*Model 3-quadratic trend
reghdfe rep_unopposed any_shooting_in_county_year_big    , absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave any_shooting_in_county_year_big using "who_runs.dta", detail(all) addlabel(outcome, Republican Runs Unopposed, treatment, Any School Shooting (Only Mass), model, quadratic trend, model_num, 3) append

reghdfe unopposed any_shooting_in_county_year_big    , absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave any_shooting_in_county_year_big using "who_runs.dta", detail(all) addlabel(outcome, Democrat Runs Unopposed, treatment, Any School Shooting (Only Mass), model, quadratic trend, model_num, 3) append

reghdfe unopposed_either any_shooting_in_county_year_big    , absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave any_shooting_in_county_year_big using "who_runs.dta", detail(all) addlabel(outcome, Either Party Runs Unopposed, treatment, Any School Shooting (Only Mass), model, quadratic trend, model_num, 3) append

*************** Deaths and Injuries

*Model 1-two way
reghdfe rep_unopposed deaths_and_injuries_std    , absorb( fips year ) cluster(fips)
regsave deaths_and_injuries_std using "who_runs.dta", detail(all) addlabel(outcome, Republican Runs Unopposed, treatment, Deaths and Injuries (Std.), model, two way, model_num, 1) append

reghdfe unopposed deaths_and_injuries_std    , absorb( fips year) cluster(fips)
regsave deaths_and_injuries_std using "who_runs.dta", detail(all) addlabel(outcome, Democrat Runs Unopposed, treatment, Deaths and Injuries (Std.), model, two way, model_num, 1) append

reghdfe unopposed_either deaths_and_injuries_std    , absorb( fips year) cluster(fips)
regsave deaths_and_injuries_std using "who_runs.dta", detail(all) addlabel(outcome, Either Party Runs Unopposed, treatment, Deaths and Injuries (Std.), model, two way, model_num, 1) append

*Model 2-linear trend
reghdfe rep_unopposed deaths_and_injuries_std    , absorb( fips year c.year#i.fips) cluster(fips)
regsave deaths_and_injuries_std using "who_runs.dta", detail(all) addlabel(outcome, Republican Runs Unopposed, treatment, Deaths and Injuries (Std.), model, linear trend, model_num, 2) append

reghdfe unopposed deaths_and_injuries_std    , absorb( fips year c.year#i.fips) cluster(fips)
regsave deaths_and_injuries_std using "who_runs.dta", detail(all) addlabel(outcome, Democrat Runs Unopposed, treatment, Deaths and Injuries (Std.), model, linear trend, model_num, 2) append

reghdfe unopposed_either deaths_and_injuries_std    , absorb( fips year c.year#i.fips) cluster(fips)
regsave deaths_and_injuries_std using "who_runs.dta", detail(all) addlabel(outcome, Either Party Runs Unopposed, treatment, Deaths and Injuries (Std.), model, linear trend, model_num, 2) append

*Model 3-quadratic trend
reghdfe rep_unopposed deaths_and_injuries_std    , absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave deaths_and_injuries_std using "who_runs.dta", detail(all) addlabel(outcome, Republican Runs Unopposed, treatment, Deaths and Injuries (Std.), model, quadratic trend, model_num, 3) append

reghdfe unopposed deaths_and_injuries_std    , absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave deaths_and_injuries_std using "who_runs.dta", detail(all) addlabel(outcome, Democrat Runs Unopposed, treatment, Deaths and Injuries (Std.), model, quadratic trend, model_num, 3) append

reghdfe unopposed_either deaths_and_injuries_std    , absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave deaths_and_injuries_std using "who_runs.dta", detail(all) addlabel(outcome, Either Party Runs Unopposed, treatment, Deaths and Injuries (Std.), model, quadratic trend, model_num, 3) append

*************** Deaths and Injuries

*Model 1-two way
reghdfe rep_unopposed reverse_min_distance_year_s    , absorb( fips year ) cluster(fips)
regsave reverse_min_distance_year_s using "who_runs.dta", detail(all) addlabel(outcome, Republican Runs Unopposed, treatment, Distance to Closest Shooting (Std.), model, two way, model_num, 1) append

reghdfe unopposed reverse_min_distance_year_s    , absorb( fips year) cluster(fips)
regsave reverse_min_distance_year_s using "who_runs.dta", detail(all) addlabel(outcome, Democrat Runs Unopposed, treatment, Distance to Closest Shooting (Std.), model, two way, model_num, 1) append

reghdfe unopposed_either reverse_min_distance_year_s    , absorb( fips year) cluster(fips)
regsave reverse_min_distance_year_s using "who_runs.dta", detail(all) addlabel(outcome, Either Party Runs Unopposed, treatment, Distance to Closest Shooting (Std.), model, two way, model_num, 1) append

*Model 2-linear trend
reghdfe rep_unopposed reverse_min_distance_year_s    , absorb( fips year c.year#i.fips) cluster(fips)
regsave reverse_min_distance_year_s using "who_runs.dta", detail(all) addlabel(outcome, Republican Runs Unopposed, treatment, Distance to Closest Shooting (Std.), model, linear trend, model_num, 2) append

reghdfe unopposed reverse_min_distance_year_s    , absorb( fips year c.year#i.fips) cluster(fips)
regsave reverse_min_distance_year_s using "who_runs.dta", detail(all) addlabel(outcome, Democrat Runs Unopposed, treatment, Distance to Closest Shooting (Std.), model, linear trend, model_num, 2) append

reghdfe unopposed_either reverse_min_distance_year_s    , absorb( fips year c.year#i.fips) cluster(fips)
regsave reverse_min_distance_year_s using "who_runs.dta", detail(all) addlabel(outcome, Either Party Runs Unopposed, treatment, Distance to Closest Shooting (Std.), model, linear trend, model_num, 2) append

*Model 3-quadratic trend
reghdfe rep_unopposed reverse_min_distance_year_s    , absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave reverse_min_distance_year_s using "who_runs.dta", detail(all) addlabel(outcome, Republican Runs Unopposed, treatment, Distance to Closest Shooting (Std.), model, quadratic trend, model_num, 3) append

reghdfe unopposed reverse_min_distance_year_s    , absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave reverse_min_distance_year_s using "who_runs.dta", detail(all) addlabel(outcome, Democrat Runs Unopposed, treatment, Distance to Closest Shooting (Std.), model, quadratic trend, model_num, 3) append

reghdfe unopposed_either reverse_min_distance_year_s    , absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave reverse_min_distance_year_s using "who_runs.dta", detail(all) addlabel(outcome, Either Party Runs Unopposed, treatment, Distance to Closest Shooting (Std.), model, quadratic trend, model_num, 3) append

use "who_runs.dta", clear
capture drop t_stat significant
gen t_stat=coef/stderr
gen significant=1 if t_stat>1.96 | t_stat<-1.96
replace significant=0 if t_stat<1.96 & t_stat>-1.96

tab significant

keep if outcome=="Republican Runs Unopposed"

saveold "who_runs_republicans_cleaned.dta", version(12) replace

use "who_runs.dta", clear
capture drop t_stat significant
gen t_stat=coef/stderr
gen significant=1 if t_stat>1.96 | t_stat<-1.96
replace significant=0 if t_stat<1.96 & t_stat>-1.96

tab significant

keep if outcome=="Democrat Runs Unopposed"

saveold "who_runs_democrats_cleaned.dta", version(12) replace

use "who_runs.dta", clear
capture drop t_stat significant
gen t_stat=coef/stderr
gen significant=1 if t_stat>1.96 | t_stat<-1.96
replace significant=0 if t_stat<1.96 & t_stat>-1.96

tab significant

keep if outcome=="Either Party Runs Unopposed"

saveold "who_runs_either_cleaned.dta", version(12) replace



*****************************************************************************************************************************
***************************************** Just the Shootings Closest to the Election (Fig A7) *******************************
*****************************************************************************************************************************

use "Shooting Distance Date Reshape 2006-2014_full.dta", clear

gen year2=year*year

gen close_shooting=1 if distance_closest_eday<=100
replace close_shooting=0 if distance_closest_eday>100 & distance_closest_eday~=.

gen close_2_shooting=1 if distance_2closest_eday<=100
replace close_2_shooting=0 if distance_2closest_eday>100 & distance_2closest_eday~=.


*****Without Linear Time Trends for Counties

****Turnout, no timing accounted
reghdfe turnout_pop close_shooting close_2_shooting unopposed rep_unopposed, absorb( fips year) cluster(fips)
regsave close_shooting close_2_shooting using "election_outcomes_results_dummy_treat.dta", detail(all) addlabel(outcome, Voter Turnout, model, no timing no trend, model_num, 1) replace 

****Turnout, timing accounted
reghdfe turnout_pop close_shooting c.close_shooting#c.c_days_before_eday close_2_shooting  close_2_shooting#c.c_2_days_before_eday unopposed rep_unopposed, absorb( fips year) cluster(fips)
regsave close_shooting close_2_shooting using "election_outcomes_results_dummy_treat.dta", detail(all) addlabel(outcome, Voter Turnout, model, yes timing no trend, model_num, 2) append 

****Dem Vote Share, no timing accounted
reghdfe dem_two_party close_shooting close_2_shooting unopposed rep_unopposed, absorb( fips year) cluster(fips)
regsave close_shooting close_2_shooting using "election_outcomes_results_dummy_treat.dta", detail(all) addlabel(outcome, Democratic Vote Share, model, no timing no trend, model_num, 1) append 

****Dem Vote Share, timing accounted
reghdfe dem_two_party close_shooting c.close_shooting#c.c_days_before_eday close_2_shooting  close_2_shooting#c.c_2_days_before_eday unopposed rep_unopposed, absorb( fips year) cluster(fips)
regsave close_shooting close_2_shooting using "election_outcomes_results_dummy_treat.dta", detail(all) addlabel(outcome, Democratic Vote Share, model, yes timing no trend, model_num, 2) append 


*****With Linear Time Trends for Counties

****Turnout, no timing accounted
reghdfe turnout_pop close_shooting close_2_shooting unopposed rep_unopposed, absorb( fips year c.year#i.fips) cluster(fips)
regsave close_shooting close_2_shooting using "election_outcomes_results_dummy_treat.dta", detail(all) addlabel(outcome, Voter Turnout, model, no timing yes trend, model_num, 3) append 

****Turnout, timing accounted
reghdfe turnout_pop close_shooting c.close_shooting#c.c_days_before_eday close_2_shooting  close_2_shooting#c.c_2_days_before_eday unopposed rep_unopposed, absorb( fips year c.year#i.fips) cluster(fips)
regsave close_shooting close_2_shooting using "election_outcomes_results_dummy_treat.dta", detail(all) addlabel(outcome, Voter Turnout, model, yes timing yes trend, model_num, 4) append 

****Dem Vote Share, no timing accounted
reghdfe dem_two_party close_shooting close_2_shooting unopposed rep_unopposed, absorb( fips year c.year#i.fips) cluster(fips)
regsave close_shooting close_2_shooting using "election_outcomes_results_dummy_treat.dta", detail(all) addlabel(outcome, Democratic Vote Share, model, no timing yes trend, model_num, 3) append 

****Dem Vote Share, timing accounted
reghdfe dem_two_party close_shooting c.close_shooting#c.c_days_before_eday close_2_shooting  c.close_2_shooting#c.c_2_days_before_eday unopposed rep_unopposed, absorb( fips year c.year#i.fips) cluster(fips)
regsave close_shooting close_2_shooting using "election_outcomes_results_dummy_treat.dta", detail(all) addlabel(outcome, Democratic Vote Share, model, yes timing yes trend, model_num,4) append


use "election_outcomes_results_dummy_treat.dta", clear
capture drop cmdline  
replace var="Shooting Closest to Election Day" if var=="close_shooting"
replace var="Shooting Second Closest to Election Day" if var=="close_2_shooting"

drop if stderr==0 // colinearity issues

saveold "election_outcomes_results_dummy_treat.dta", version(12) replace
 

*****************************************************************************************************************************
***************************************** Extended Time Series (2000-2018; Fig A11) *****************************************
*****************************************************************************************************************************

**** Merging Shootings and Longer Time Series Together
use "Shooting Location Extended with County Cleaned.dta", clear

drop if state=="DC"

rename cnty_fips county_fips

merge 1:1 county_fips state_fips year using "extended time series/county_dem_vote_share_2000_2018.dta", gen(_merge_vs)

foreach var in Deaths Injuries any_shooting_in_county_year {
replace `var'=0 if `var'==.
}

countyfips, c(county_fips) statefips(state_fips)

gen unopposed=1 if dem_perc>=0.95 & dem_perc~=.
replace unopposed=0 if dem_perc<0.95 //

gen rep_unopposed=1 if dem_perc<=0.05 // Republican dominated
replace rep_unopposed=0 if dem_perc>0.05 & dem_perc~=.  // Republican dominated

gen unopposed_either =1 if dem_perc>=0.95 & dem_perc~=.
replace unopposed_either =1 if dem_perc<0.05 
replace unopposed_either =0 if dem_perc<0.95 & dem_perc>=0.05 

gen year2=year*year

gen deaths_and_injuries=Injuries+Deaths
egen deaths_and_injuries_std=std(deaths_and_injuries), mean(0) std(1)
egen deaths_std=std(Deaths), mean(0) std(1)
egen injuries_std=std(Injuries), mean(0) std(1)

gen any_shooting_in_county_year_big=any_shooting_in_county_year
replace any_shooting_in_county_year_big=. if deaths_and_injuries<4 & deaths_and_injuries>0

save "extended time series/county_dem_vote_share_2000_2018.dta_with_shootings", replace

*********************** Models Start Here

use "extended time series/county_dem_vote_share_2000_2018.dta_with_shootings", clear

** All Shootings No Controls Two Way Fixed Effects
reghdfe dem_perc any_shooting_in_county_year , absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year using "election_results_longer_time_series.dta", detail(all) addlabel(treatment, Any School Shooting, outcome, Democratic Vote Share, model, two way fe, controls, none, model_num, 1) replace 

** All Shootings Controlling for Dem/Rep Unopposed Races Two Way Fixed Effects
reghdfe dem_perc any_shooting_in_county_year rep_unopposed unopposed, absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year using "election_results_longer_time_series.dta", detail(all) addlabel(treatment, Any School Shooting, outcome,  Democratic Vote Share, model, two way fe, controls, unopposed, model_num, 2) append 

** All Shootings, Two Way Fixed Effects + Linear Trends
reghdfe dem_perc any_shooting_in_county_year  rep_unopposed unopposed , absorb( fips year c.year#i.fips) cluster(fips)
regsave any_shooting_in_county_year using "election_results_longer_time_series.dta", detail(all) addlabel(treatment, Any School Shooting, outcome,  Democratic Vote Share, model, linear time trend, controls, unopposed, model_num, 3) append 

** All Shootings, Two Way Fixed Effects + Quadratic Trends
reghdfe dem_perc any_shooting_in_county_year   rep_unopposed unopposed, absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave any_shooting_in_county_year using "election_results_longer_time_series.dta", detail(all) addlabel(treatment, Any School Shooting, outcome,  Democratic Vote Share, model, quadratic time trend, controls, unopposed, model_num, 4) append 


** All BIG Shootings No Controls Two Way Fixed Effects
reghdfe dem_perc any_shooting_in_county_year_big , absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year_big using "election_results_longer_time_series.dta", detail(all) addlabel(treatment, Any School Shooting (Only Mass), outcome, Democratic Vote Share, model, two way fe, controls, none, model_num, 1) append 

** All BIG Shootings Controlling for Dem/Rep Unopposed Races Two Way Fixed Effects
reghdfe dem_perc any_shooting_in_county_year_big rep_unopposed unopposed, absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year_big using "election_results_longer_time_series.dta", detail(all) addlabel(treatment, Any School Shooting (Only Mass), outcome,  Democratic Vote Share, model, two way fe, controls, unopposed, model_num, 2) append 

** All BIG Shootings, Two Way Fixed Effects + Linear Trends
reghdfe dem_perc any_shooting_in_county_year_big  rep_unopposed unopposed , absorb( fips year c.year#i.fips) cluster(fips)
regsave any_shooting_in_county_year_big using "election_results_longer_time_series.dta", detail(all) addlabel(treatment, Any School Shooting (Only Mass), outcome,  Democratic Vote Share, model, linear time trend, controls, unopposed, model_num, 3) append 

** All BIG Shootings, Two Way Fixed Effects + Quadratic Trends
reghdfe dem_perc any_shooting_in_county_year_big   rep_unopposed unopposed, absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave any_shooting_in_county_year_big using "election_results_longer_time_series.dta", detail(all) addlabel(treatment, Any School Shooting (Only Mass), outcome,  Democratic Vote Share, model, quadratic time trend, controls, unopposed, model_num, 4) append 


** All BIG Shootings No Controls Two Way Fixed Effects
reghdfe dem_perc deaths_and_injuries_std , absorb( fips year) cluster(fips)
regsave deaths_and_injuries_std using "election_results_longer_time_series.dta", detail(all) addlabel(treatment, Deaths and Injuries (Std.), outcome, Democratic Vote Share, model, two way fe, controls, none, model_num, 1) append 

** All BIG Shootings Controlling for Dem/Rep Unopposed Races Two Way Fixed Effects
reghdfe dem_perc deaths_and_injuries_std rep_unopposed unopposed, absorb( fips year) cluster(fips)
regsave deaths_and_injuries_std using "election_results_longer_time_series.dta", detail(all) addlabel(treatment, Deaths and Injuries (Std.), outcome,  Democratic Vote Share, model, two way fe, controls, unopposed, model_num, 2) append 

** All BIG Shootings, Two Way Fixed Effects + Linear Trends
reghdfe dem_perc deaths_and_injuries_std  rep_unopposed unopposed , absorb( fips year c.year#i.fips) cluster(fips)
regsave deaths_and_injuries_std using "election_results_longer_time_series.dta", detail(all) addlabel(treatment, Deaths and Injuries (Std.), outcome,  Democratic Vote Share, model, linear time trend, controls, unopposed, model_num, 3) append 

** All BIG Shootings, Two Way Fixed Effects + Quadratic Trends
reghdfe dem_perc deaths_and_injuries_std   rep_unopposed unopposed, absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave deaths_and_injuries_std using "election_results_longer_time_series.dta", detail(all) addlabel(treatment, Deaths and Injuries (Std.), outcome,  Democratic Vote Share, model, quadratic time trend, controls, unopposed, model_num, 4) append 


use "election_results_longer_time_series.dta", clear

gen t_stat=coef/stderr
gen significant=1 if t_stat>1.96 | t_stat<-1.96
replace significant=0 if t_stat<1.96 & t_stat>-1.96

tab significant

saveold "election_results_longer_time_series.dta", version(12) replace

*****************************************************************************************************************************
***************************************** Stratifying by Lagged *************************************************************
*****************************************************************************************************************************

use "Shooting Distance Date Reshape 2006-2014_full.dta", clear

sort fips year
gen dem_two_party_lag = dem_two_party[_n-1] if fips==fips[_n-1] & year > year[_n-1] 

gen year2=year*year

sum dem_two_party_lag, d

*Effects in high dem areas
reghdfe dem_perc any_shooting_in_county_year   rep_unopposed unopposed if dem_two_party_lag>=.4052424 & dem_two_party_lag~=. , absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
*Effects in low dem areas
reghdfe dem_perc any_shooting_in_county_year   rep_unopposed unopposed if dem_two_party_lag<.4052424 , absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)



*****************************************************************************************************************************
***************************************** Quantile Regression (Fig A12) *****************************************************
*****************************************************************************************************************************

use "Shooting Distance Date Reshape 2006-2014_full.dta", clear

gen year2=year*year

xtqreg dem_two_party any_shooting_in_county_year unopposed rep_unopposed i.year, i( fips)  q(0.1)
regsave any_shooting_in_county_year using "qunatile_regression_results.dta", detail(all) addlabel(treatment, Any Shooting, outcome,  Democratic Vote Share, model, two way, controls, unopposed, quantile, 0.1) replace 

xtqreg dem_two_party any_shooting_in_county_year unopposed rep_unopposed i.year, i( fips)  q(0.2)
regsave any_shooting_in_county_year using "qunatile_regression_results.dta", detail(all) addlabel(treatment, Any Shooting, outcome,  Democratic Vote Share, model, two way, controls, unopposed, quantile, 0.2) append 

xtqreg dem_two_party any_shooting_in_county_year unopposed rep_unopposed i.year, i( fips)  q(0.3)
regsave any_shooting_in_county_year using "qunatile_regression_results.dta", detail(all) addlabel(treatment, Any Shooting, outcome,  Democratic Vote Share, model, two way, controls, unopposed, quantile, 0.3) append 

xtqreg dem_two_party any_shooting_in_county_year unopposed rep_unopposed i.year, i( fips)  q(0.4)
regsave any_shooting_in_county_year using "qunatile_regression_results.dta", detail(all) addlabel(treatment, Any Shooting, outcome,  Democratic Vote Share, model, two way, controls, unopposed, quantile, 0.4) append 

xtqreg dem_two_party any_shooting_in_county_year unopposed rep_unopposed i.year, i( fips)  q(0.5)
regsave any_shooting_in_county_year using "qunatile_regression_results.dta", detail(all) addlabel(treatment, Any Shooting, outcome,  Democratic Vote Share, model, two way, controls, unopposed, quantile, 0.5) append 

xtqreg dem_two_party any_shooting_in_county_year unopposed rep_unopposed i.year, i( fips)  q(0.6)
regsave any_shooting_in_county_year using "qunatile_regression_results.dta", detail(all) addlabel(treatment, Any Shooting, outcome,  Democratic Vote Share, model, two way, controls, unopposed, quantile, 0.6) append 

xtqreg dem_two_party any_shooting_in_county_year unopposed rep_unopposed i.year, i( fips)  q(0.7)
regsave any_shooting_in_county_year using "qunatile_regression_results.dta", detail(all) addlabel(treatment, Any Shooting, outcome,  Democratic Vote Share, model, two way, controls, unopposed, quantile, 0.7) append 

xtqreg dem_two_party any_shooting_in_county_year unopposed rep_unopposed i.year, i( fips)  q(0.8)
regsave any_shooting_in_county_year using "qunatile_regression_results.dta", detail(all) addlabel(treatment, Any Shooting, outcome,  Democratic Vote Share, model, two way, controls, unopposed, quantile, 0.8) append 

xtqreg dem_two_party any_shooting_in_county_year unopposed rep_unopposed i.year, i( fips)  q(0.9)
regsave any_shooting_in_county_year using "qunatile_regression_results.dta", detail(all) addlabel(treatment, Any Shooting, outcome,  Democratic Vote Share, model, two way, controls, unopposed, quantile, 0.9) append 

use "qunatile_regression_results.dta", clear

gen t_stat=coef/stderr
gen significant=1 if t_stat>1.96 | t_stat<-1.96
replace significant=0 if t_stat<1.96 & t_stat>-1.96

tab significant

saveold "qunatile_regression_results.dta", version(12) replace

*****************************************************************************************************************************
***************************************** Starndardized Effects -- Vote Share (Fig A13) *************************************
*****************************************************************************************************************************


use "Shooting Distance Date Reshape 2006-2014_full.dta", clear

gen year2=year*year

egen dem_two_party_std=std(dem_two_part), mean(0) std(1)

*************** ALL SHOOTINGS (0/1)

** All Shootings No Controls Two Way Fixed Effects
reghdfe dem_two_party_std any_shooting_in_county_year , absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year using "election_outcomes_results_updated_standarized.dta", detail(all) addlabel(treatment, any shooting, outcome, Democratic Vote Share, model, two way fe, controls, none, model_num, 1) replace 

** All Shootings Controlling for Dem/Rep Unopposed Races Two Way Fixed Effects
reghdfe dem_two_party_std any_shooting_in_county_year rep_unopposed unopposed, absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year using "election_outcomes_results_updated_standarized.dta", detail(all) addlabel(treatment, any shooting, outcome, Democratic Vote Share, model, two way fe, controls, unopposed, model_num, 2) append 

** All Shootings, Two Way Fixed Effects + Linear Trends
reghdfe dem_two_party_std any_shooting_in_county_year  rep_unopposed unopposed , absorb( fips year c.year#i.fips) cluster(fips)
regsave any_shooting_in_county_year using "election_outcomes_results_updated_standarized.dta", detail(all) addlabel(treatment, any shooting, outcome, Democratic Vote Share, model, linear time trend, controls, unopposed, model_num, 3) append 

** All Shootings, Two Way Fixed Effects + Quadratic Trends
reghdfe dem_two_party_std any_shooting_in_county_year   rep_unopposed unopposed, absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave any_shooting_in_county_year using "election_outcomes_results_updated_standarized.dta", detail(all) addlabel(treatment, any shooting, outcome, Democratic Vote Share, model, quadratic time trend, controls, unopposed, model_num, 4) append 

************** BIG SHOOTINGS (0/1)

gen deaths_and_injuries=Injuries+Deaths

gen any_shooting_in_county_year_big=any_shooting_in_county_year
replace any_shooting_in_county_year_big=. if deaths_and_injuries<4 & deaths_and_injuries>0

** Big Shootings No Controls Two Way Fixed Effects
reghdfe dem_two_party_std any_shooting_in_county_year_big , absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year_big using "election_outcomes_results_updated_standarized.dta", detail(all) addlabel(treatment, any big shooting, outcome, Democratic Vote Share, model, two way fe, controls, none, model_num, 1) append 

** Big Shootings Controlling for Dem/Rep Unopposed Races Two Way Fixed Effects
reghdfe dem_two_party_std any_shooting_in_county_year_big rep_unopposed unopposed, absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year_big using "election_outcomes_results_updated_standarized.dta", detail(all) addlabel(treatment, any big shooting, outcome, Democratic Vote Share, model, two way fe, controls, unopposed, model_num, 2) append 

** Big Shootings, Two Way Fixed Effects + Linear Trends
reghdfe dem_two_party_std any_shooting_in_county_year_big  rep_unopposed unopposed , absorb( fips year c.year#i.fips) cluster(fips)
regsave any_shooting_in_county_year_big using "election_outcomes_results_updated_standarized.dta", detail(all) addlabel(treatment, any big shooting, outcome, Democratic Vote Share, model, linear time trend, controls, unopposed, model_num, 3) append 

** Big Shootings, Two Way Fixed Effects + Quadratic Trends
reghdfe dem_two_party_std any_shooting_in_county_year_big  rep_unopposed unopposed , absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave any_shooting_in_county_year_big using "election_outcomes_results_updated_standarized.dta", detail(all) addlabel(treatment, any big shooting, outcome, Democratic Vote Share, model, quadratic time trend, controls, unopposed, model_num, 4) append 


************** DEATHS + INJURIES (continuous)

egen deaths_and_injuries_std=std(deaths_and_injuries), mean(0) std(1)
egen deaths_std=std(Deaths), mean(0) std(1)
egen injuries_std=std(Injuries), mean(0) std(1)

** No Controls Two Way Fixed Effects
reghdfe dem_two_party_std deaths_and_injuries_std , absorb( fips year) cluster(fips)
regsave deaths_and_injuries_std using "election_outcomes_results_updated_standarized.dta", detail(all) addlabel(treatment, deaths and injuries standardize, outcome, Democratic Vote Share, model, two way fe, controls, none, model_num, 1) append 

** Controlling for Dem/Rep Unopposed Races Two Way Fixed Effects
reghdfe dem_two_party_std deaths_and_injuries_std rep_unopposed unopposed, absorb( fips year) cluster(fips)
regsave deaths_and_injuries_std using "election_outcomes_results_updated_standarized.dta", detail(all) addlabel(treatment, deaths and injuries standardize, outcome, Democratic Vote Share, model, two way fe, controls, unopposed, model_num, 2) append 

** Two Way Fixed Effects + Linear Trends
reghdfe dem_two_party_std deaths_and_injuries_std  rep_unopposed unopposed , absorb( fips year c.year#i.fips) cluster(fips)
regsave deaths_and_injuries_std using "election_outcomes_results_updated_standarized.dta", detail(all) addlabel(treatment, deaths and injuries standardize, outcome, Democratic Vote Share, model, linear time trend, controls, unopposed, model_num, 3) append 

** Two Way Fixed Effects + Quadratic Trends
reghdfe dem_two_party_std deaths_and_injuries_std  rep_unopposed unopposed , absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave deaths_and_injuries_std using "election_outcomes_results_updated_standarized.dta", detail(all) addlabel(treatment, deaths and injuries standardize, outcome, Democratic Vote Share, model, quadratic time trend, controls, unopposed, model_num, 4) append 


************** CLOSE BY TREATED (ALL YEAR)

egen min_dist_shoot_year=rowmin(distance_11closest_eday distance_10closest_eday distance_9closest_eday distance_8closest_eday distance_7closest_eday distance_6closest_eday distance_5closest_eday distance_4closest_eday distance_3closest_eday distance_2closest_eday distance_closest_eday distance_33closest_eday distance_32closest_eday distance_31closest_eday distance_30closest_eday distance_29closest_eday distance_28closest_eday distance_27closest_eday distance_26closest_eday distance_25closest_eday distance_24closest_eday distance_23closest_eday distance_22closest_eday distance_21closest_eday distance_20closest_eday distance_19closest_eday distance_18closest_eday distance_17closest_eday distance_16closest_eday distance_15closest_eday distance_14closest_eday distance_13closest_eday distance_12closest_eday)

gen reverse_min_distance_year=-min_dist_shoot_year
egen reverse_min_distance_year_s=std(reverse_min_distance_year), mean(0) std(1)

** No Controls Two Way Fixed Effects
reghdfe dem_two_party_std reverse_min_distance_year_s , absorb( fips year) cluster(fips)
regsave reverse_min_distance_year_s using "election_outcomes_results_updated_standarized.dta", detail(all) addlabel(treatment, close by shooting, outcome, Democratic Vote Share, model, two way fe, controls, none, model_num, 1) append 

** Controlling for Dem/Rep Unopposed Races Two Way Fixed Effects
reghdfe dem_two_party_std reverse_min_distance_year_s rep_unopposed unopposed, absorb( fips year) cluster(fips)
regsave reverse_min_distance_year_s using "election_outcomes_results_updated_standarized.dta", detail(all) addlabel(treatment, close by shooting, outcome, Democratic Vote Share, model, two way fe, controls, unopposed, model_num, 2) append 

** Two Way Fixed Effects + Linear Trends
sum distance_closest_eday, d // 25th percentile
reghdfe dem_two_party_std reverse_min_distance_year_s  rep_unopposed unopposed , absorb( fips year c.year#i.fips) cluster(fips)
regsave reverse_min_distance_year_s using "election_outcomes_results_updated_standarized.dta", detail(all) addlabel(treatment, close by shooting, outcome, Democratic Vote Share, model, linear time trend, controls, unopposed, model_num, 3) append 

** Two Way Fixed Effects + Quadratic Trends
reghdfe dem_two_party_std reverse_min_distance_year_s  rep_unopposed unopposed , absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave reverse_min_distance_year_s using "election_outcomes_results_updated_standarized.dta", detail(all) addlabel(treatment, close by shooting, outcome, Democratic Vote Share, model, quadratic time trend, controls, unopposed, model_num, 4) append 

use "election_outcomes_results_updated_standarized.dta", clear

gen t_stat=coef/stderr
gen significant=1 if t_stat>1.96 | t_stat<-1.96
replace significant=0 if t_stat<1.96 & t_stat>-1.96

tab significant

replace var="Distance to Closest Shooting (Std.)" if var=="reverse_min_distance_year_s"
replace var="Deaths and Injuries (Std.)" if var=="deaths_and_injuries_std"
replace var="Any School Shooting (Only Mass)" if var=="any_shooting_in_county_year_big"
replace var="Any School Shooting" if var=="any_shooting_in_county_year"

saveold "election_outcomes_results_updated_standarized_cleaned.dta", version(12) replace


*****************************************************************************************************************************
***************************************** Starndardized Effects -- Voter Turnout (Fig A14) **********************************
*****************************************************************************************************************************


use "Shooting Distance Date Reshape 2006-2014_full.dta", clear

gen year2=year*year

egen turnout_pop_std=std(turnout_pop), mean(0) std(1)

*************** ALL SHOOTINGS (0/1)

** All Shootings No Controls Two Way Fixed Effects
reghdfe turnout_pop_std any_shooting_in_county_year , absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year using "turnout_results_updated_standardized.dta", detail(all) addlabel(treatment, any shooting, outcome, Voter Turnout, model, two way fe, controls, none, model_num, 1) replace 

** All Shootings Controlling for Dem/Rep Unopposed Races Two Way Fixed Effects
reghdfe turnout_pop_std any_shooting_in_county_year rep_unopposed unopposed, absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year using "turnout_results_updated_standardized.dta", detail(all) addlabel(treatment, any shooting, outcome, Voter Turnout, model, two way fe, controls, unopposed, model_num, 2) append 

** All Shootings, Two Way Fixed Effects + Linear Trends
reghdfe turnout_pop_std any_shooting_in_county_year  rep_unopposed unopposed , absorb( fips year c.year#i.fips) cluster(fips)
regsave any_shooting_in_county_year using "turnout_results_updated_standardized.dta", detail(all) addlabel(treatment, any shooting, outcome, Voter Turnout, model, linear time trend, controls, unopposed, model_num, 3) append 

** All Shootings, Two Way Fixed Effects + Quadratic Trends
reghdfe turnout_pop_std any_shooting_in_county_year   rep_unopposed unopposed, absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave any_shooting_in_county_year using "turnout_results_updated_standardized.dta", detail(all) addlabel(treatment, any shooting, outcome, Voter Turnout, model, quadratic time trend, controls, unopposed, model_num, 4) append 

************** BIG SHOOTINGS (0/1)

gen deaths_and_injuries=Injuries+Deaths

gen any_shooting_in_county_year_big=any_shooting_in_county_year
replace any_shooting_in_county_year_big=. if deaths_and_injuries<4 & deaths_and_injuries>0

** Big Shootings No Controls Two Way Fixed Effects
reghdfe turnout_pop_std any_shooting_in_county_year_big , absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year_big using "turnout_results_updated_standardized.dta", detail(all) addlabel(treatment, any big shooting, outcome, Voter Turnout, model, two way fe, controls, none, model_num, 1) append 

** Big Shootings Controlling for Dem/Rep Unopposed Races Two Way Fixed Effects
reghdfe turnout_pop_std any_shooting_in_county_year_big rep_unopposed unopposed, absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year_big using "turnout_results_updated_standardized.dta", detail(all) addlabel(treatment, any big shooting, outcome, Voter Turnout, model, two way fe, controls, unopposed, model_num, 2) append 

** Big Shootings, Two Way Fixed Effects + Linear Trends
reghdfe turnout_pop_std any_shooting_in_county_year_big  rep_unopposed unopposed , absorb( fips year c.year#i.fips) cluster(fips)
regsave any_shooting_in_county_year_big using "turnout_results_updated_standardized.dta", detail(all) addlabel(treatment, any big shooting, outcome, Voter Turnout, model, linear time trend, controls, unopposed, model_num, 3) append 

** Big Shootings, Two Way Fixed Effects + Quadratic Trends
reghdfe turnout_pop_std any_shooting_in_county_year_big  rep_unopposed unopposed , absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave any_shooting_in_county_year_big using "turnout_results_updated_standardized.dta", detail(all) addlabel(treatment, any big shooting, outcome, Voter Turnout, model, quadratic time trend, controls, unopposed, model_num, 4) append 


************** DEATHS + INJURIES (continuous)

egen deaths_and_injuries_std=std(deaths_and_injuries), mean(0) std(1)
egen deaths_std=std(Deaths), mean(0) std(1)
egen injuries_std=std(Injuries), mean(0) std(1)

** No Controls Two Way Fixed Effects
reghdfe turnout_pop_std deaths_and_injuries_std , absorb( fips year) cluster(fips)
regsave deaths_and_injuries_std using "turnout_results_updated_standardized.dta", detail(all) addlabel(treatment, deaths and injuries standardize, outcome, Voter Turnout, model, two way fe, controls, none, model_num, 1) append 

** Controlling for Dem/Rep Unopposed Races Two Way Fixed Effects
reghdfe turnout_pop_std deaths_and_injuries_std rep_unopposed unopposed, absorb( fips year) cluster(fips)
regsave deaths_and_injuries_std using "turnout_results_updated_standardized.dta", detail(all) addlabel(treatment, deaths and injuries standardize, outcome, Voter Turnout, model, two way fe, controls, unopposed, model_num, 2) append 

** Two Way Fixed Effects + Linear Trends
reghdfe turnout_pop_std deaths_and_injuries_std  rep_unopposed unopposed , absorb( fips year c.year#i.fips) cluster(fips)
regsave deaths_and_injuries_std using "turnout_results_updated_standardized.dta", detail(all) addlabel(treatment, deaths and injuries standardize, outcome, Voter Turnout, model, linear time trend, controls, unopposed, model_num, 3) append 

** Two Way Fixed Effects + Quadratic Trends
reghdfe turnout_pop_std deaths_and_injuries_std  rep_unopposed unopposed , absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave deaths_and_injuries_std using "turnout_results_updated_standardized.dta", detail(all) addlabel(treatment, deaths and injuries standardize, outcome, Voter Turnout, model, quadratic time trend, controls, unopposed, model_num, 4) append 

************** CLOSE BY TREATED (ALL YEAR)

egen min_dist_shoot_year=rowmin(distance_11closest_eday distance_10closest_eday distance_9closest_eday distance_8closest_eday distance_7closest_eday distance_6closest_eday distance_5closest_eday distance_4closest_eday distance_3closest_eday distance_2closest_eday distance_closest_eday distance_33closest_eday distance_32closest_eday distance_31closest_eday distance_30closest_eday distance_29closest_eday distance_28closest_eday distance_27closest_eday distance_26closest_eday distance_25closest_eday distance_24closest_eday distance_23closest_eday distance_22closest_eday distance_21closest_eday distance_20closest_eday distance_19closest_eday distance_18closest_eday distance_17closest_eday distance_16closest_eday distance_15closest_eday distance_14closest_eday distance_13closest_eday distance_12closest_eday)

gen reverse_min_distance_year=-min_dist_shoot_year
egen reverse_min_distance_year_s=std(reverse_min_distance_year), mean(0) std(1)

** No Controls Two Way Fixed Effects
reghdfe turnout_pop_std reverse_min_distance_year_s , absorb( fips year) cluster(fips)
regsave reverse_min_distance_year_s using "turnout_results_updated_standardized.dta", detail(all) addlabel(treatment, close by shooting, outcome, Voter Turnout, model, two way fe, controls, none, model_num, 1) append 

** Controlling for Dem/Rep Unopposed Races Two Way Fixed Effects
reghdfe turnout_pop_std reverse_min_distance_year_s rep_unopposed unopposed, absorb( fips year) cluster(fips)
regsave reverse_min_distance_year_s using "turnout_results_updated_standardized.dta", detail(all) addlabel(treatment, close by shooting, outcome, Voter Turnout, model, two way fe, controls, unopposed, model_num, 2) append 

** Two Way Fixed Effects + Linear Trends
sum distance_closest_eday, d // 25th percentile
reghdfe turnout_pop_std reverse_min_distance_year_s  rep_unopposed unopposed , absorb( fips year c.year#i.fips) cluster(fips)
regsave reverse_min_distance_year_s using "turnout_results_updated_standardized.dta", detail(all) addlabel(treatment, close by shooting, outcome, Voter Turnout, model, linear time trend, controls, unopposed, model_num, 3) append 

** Two Way Fixed Effects + Quadratic Trends
reghdfe turnout_pop_std reverse_min_distance_year_s  rep_unopposed unopposed , absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave reverse_min_distance_year_s using "turnout_results_updated_standardized.dta", detail(all) addlabel(treatment, close by shooting, outcome, Voter Turnout, model, quadratic time trend, controls, unopposed, model_num, 4) append 

use "turnout_results_updated_standardized.dta", clear

gen t_stat=coef/stderr
gen significant=1 if t_stat>1.96 | t_stat<-1.96
replace significant=0 if t_stat<1.96 & t_stat>-1.96

tab significant

replace var="Distance to Closest Shooting (Std.)" if var=="reverse_min_distance_year_s"
replace var="Deaths and Injuries (Std.)" if var=="deaths_and_injuries_std"
replace var="Any School Shooting (Only Mass)" if var=="any_shooting_in_county_year_big"
replace var="Any School Shooting" if var=="any_shooting_in_county_year"

saveold "turnout_results_updated_standardized_cleaned.dta", version(12) replace


*****************************************************************************************************************************
********************Including Odd Years as Treatment in the Next Election Cycle - Vote Share (Fig A15) **********************
*****************************************************************************************************************************

use "elections_panel_cleaned.dta", clear

merge 1:1 county state year using "Shooting Location with County Cleaned Including Odd Years.dta", gen(_merge_odd_years)

foreach var in Deaths Injuries any_shooting_in_county_year {

replace `var'=0 if `var'==.

}

gen year2=year*year

egen fips=concat(county state)
encode fips, gen(fips_e)
drop fips
rename fips_e fips

gen unopposed=1 if dem_two_party>=0.95 & dem_two_party~=.
replace unopposed=0 if dem_two_party<0.95 //

gen rep_unopposed=1 if dem_two_party<=0.05 // Republican dominated
replace rep_unopposed=0 if dem_two_party>0.05 & dem_two_party~=.  // Republican dominated

gen unopposed_either =1 if dem_two_party>=0.95 & dem_two_party~=.
replace unopposed_either =1 if dem_two_party<0.05 
replace unopposed_either =0 if dem_two_party<0.95 & dem_two_party>=0.05 


*************** ALL SHOOTINGS (0/1)

** All Shootings No Controls Two Way Fixed Effects
reghdfe dem_two_party any_shooting_in_county_year , absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year using "election_outcomes_updated_odd_years.dta", detail(all) addlabel(treatment, any shooting, outcome, Democratic Vote Share, model, two way fe, controls, none, model_num, 1) replace 

** All Shootings Controlling for Dem/Rep Unopposed Races Two Way Fixed Effects
reghdfe dem_two_party any_shooting_in_county_year rep_unopposed unopposed, absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year using "election_outcomes_updated_odd_years.dta", detail(all) addlabel(treatment, any shooting, outcome, Democratic Vote Share, model, two way fe, controls, unopposed, model_num, 2) append 

** All Shootings, Two Way Fixed Effects + Linear Trends
reghdfe dem_two_party any_shooting_in_county_year  rep_unopposed unopposed , absorb( fips year c.year#i.fips) cluster(fips)
regsave any_shooting_in_county_year using "election_outcomes_updated_odd_years.dta", detail(all) addlabel(treatment, any shooting, outcome, Democratic Vote Share, model, linear time trend, controls, unopposed, model_num, 3) append 

** All Shootings, Two Way Fixed Effects + Quadratic Trends
reghdfe dem_two_party any_shooting_in_county_year   rep_unopposed unopposed, absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave any_shooting_in_county_year using "election_outcomes_updated_odd_years.dta", detail(all) addlabel(treatment, any shooting, outcome, Democratic Vote Share, model, quadratic time trend, controls, unopposed, model_num, 4) append 

************** BIG SHOOTINGS (0/1)

capture drop deaths_and_injuries any_shooting_in_county_year_big
gen deaths_and_injuries=Injuries+Deaths

gen any_shooting_in_county_year_big=any_shooting_in_county_year
replace any_shooting_in_county_year_big=. if deaths_and_injuries<4 & deaths_and_injuries>0

** Big Shootings No Controls Two Way Fixed Effects
reghdfe dem_two_party any_shooting_in_county_year_big , absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year_big using "election_outcomes_updated_odd_years.dta", detail(all) addlabel(treatment, any big shooting, outcome, Democratic Vote Share, model, two way fe, controls, none, model_num, 1) append 

** Big Shootings Controlling for Dem/Rep Unopposed Races Two Way Fixed Effects
reghdfe dem_two_party any_shooting_in_county_year_big rep_unopposed unopposed, absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year_big using "election_outcomes_updated_odd_years.dta", detail(all) addlabel(treatment, any big shooting, outcome, Democratic Vote Share, model, two way fe, controls, unopposed, model_num, 2) append 

** Big Shootings, Two Way Fixed Effects + Linear Trends
reghdfe dem_two_party any_shooting_in_county_year_big  rep_unopposed unopposed , absorb( fips year c.year#i.fips) cluster(fips)
regsave any_shooting_in_county_year_big using "election_outcomes_updated_odd_years.dta", detail(all) addlabel(treatment, any big shooting, outcome, Democratic Vote Share, model, linear time trend, controls, unopposed, model_num, 3) append 

** Big Shootings, Two Way Fixed Effects + Quadratic Trends
reghdfe dem_two_party any_shooting_in_county_year_big  rep_unopposed unopposed , absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave any_shooting_in_county_year_big using "election_outcomes_updated_odd_years.dta", detail(all) addlabel(treatment, any big shooting, outcome, Democratic Vote Share, model, quadratic time trend, controls, unopposed, model_num, 4) append 


************** DEATHS + INJURIES (continuous)

egen deaths_and_injuries_std=std(deaths_and_injuries), mean(0) std(1)
egen deaths_std=std(Deaths), mean(0) std(1)
egen injuries_std=std(Injuries), mean(0) std(1)

** No Controls Two Way Fixed Effects
reghdfe dem_two_party deaths_and_injuries , absorb( fips year) cluster(fips)
regsave deaths_and_injuries using "election_outcomes_updated_odd_years.dta", detail(all) addlabel(treatment, deaths and injuries standardize, outcome, Democratic Vote Share, model, two way fe, controls, none, model_num, 1) append 

** Controlling for Dem/Rep Unopposed Races Two Way Fixed Effects
reghdfe dem_two_party deaths_and_injuries rep_unopposed unopposed, absorb( fips year) cluster(fips)
regsave deaths_and_injuries using "election_outcomes_updated_odd_years.dta", detail(all) addlabel(treatment, deaths and injuries standardize, outcome, Democratic Vote Share, model, two way fe, controls, unopposed, model_num, 2) append 

** Two Way Fixed Effects + Linear Trends
reghdfe dem_two_party deaths_and_injuries  rep_unopposed unopposed , absorb( fips year c.year#i.fips) cluster(fips)
regsave deaths_and_injuries using "election_outcomes_updated_odd_years.dta", detail(all) addlabel(treatment, deaths and injuries standardize, outcome, Democratic Vote Share, model, linear time trend, controls, unopposed, model_num, 3) append 

** Two Way Fixed Effects + Quadratic Trends
reghdfe dem_two_party deaths_and_injuries  rep_unopposed unopposed , absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave deaths_and_injuries using "election_outcomes_updated_odd_years.dta", detail(all) addlabel(treatment, deaths and injuries standardize, outcome, Democratic Vote Share, model, quadratic time trend, controls, unopposed, model_num, 4) append 


use "election_outcomes_updated_odd_years.dta", clear

gen t_stat=coef/stderr
gen significant=1 if t_stat>1.96 | t_stat<-1.96
replace significant=0 if t_stat<1.96 & t_stat>-1.96

tab significant

replace var="Deaths and Injuries (Std.)" if var=="deaths_and_injuries"
replace var="Any School Shooting (Only Mass)" if var=="any_shooting_in_county_year_big"
replace var="Any School Shooting" if var=="any_shooting_in_county_year"

saveold "election_outcomes_updated_odd_years_cleaned.dta", version(12) replace



*****************************************************************************************************************************
********************Including Odd Years as Treatment in the Next Election Cycle - Voter Turnout (Fig A16) *******************
*****************************************************************************************************************************

use "elections_panel_cleaned.dta", clear

merge 1:1 county state year using "Shooting Location with County Cleaned Including Odd Years.dta", gen(_merge_odd_years)

foreach var in Deaths Injuries any_shooting_in_county_year {

replace `var'=0 if `var'==.

}

gen year2=year*year

egen fips=concat(county state)
encode fips, gen(fips_e)
drop fips
rename fips_e fips

gen unopposed=1 if dem_two_party>=0.95 & dem_two_party~=.
replace unopposed=0 if dem_two_party<0.95 //

gen rep_unopposed=1 if dem_two_party<=0.05 // Republican dominated
replace rep_unopposed=0 if dem_two_party>0.05 & dem_two_party~=.  // Republican dominated

gen unopposed_either =1 if dem_two_party>=0.95 & dem_two_party~=.
replace unopposed_either =1 if dem_two_party<0.05 
replace unopposed_either =0 if dem_two_party<0.95 & dem_two_party>=0.05 


*************** ALL SHOOTINGS (0/1)

** All Shootings No Controls Two Way Fixed Effects
reghdfe turnout_pop any_shooting_in_county_year , absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year using "turnout_results_updated_odd_years.dta", detail(all) addlabel(treatment, any shooting, outcome, Voter Turnout, model, two way fe, controls, none, model_num, 1) replace 

** All Shootings Controlling for Dem/Rep Unopposed Races Two Way Fixed Effects
reghdfe turnout_pop any_shooting_in_county_year rep_unopposed unopposed, absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year using "turnout_results_updated_odd_years.dta", detail(all) addlabel(treatment, any shooting, outcome, Voter Turnout, model, two way fe, controls, unopposed, model_num, 2) append 

** All Shootings, Two Way Fixed Effects + Linear Trends
reghdfe turnout_pop any_shooting_in_county_year  rep_unopposed unopposed , absorb( fips year c.year#i.fips) cluster(fips)
regsave any_shooting_in_county_year using "turnout_results_updated_odd_years.dta", detail(all) addlabel(treatment, any shooting, outcome, Voter Turnout, model, linear time trend, controls, unopposed, model_num, 3) append 

** All Shootings, Two Way Fixed Effects + Quadratic Trends
reghdfe turnout_pop any_shooting_in_county_year   rep_unopposed unopposed, absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave any_shooting_in_county_year using "turnout_results_updated_odd_years.dta", detail(all) addlabel(treatment, any shooting, outcome, Voter Turnout, model, quadratic time trend, controls, unopposed, model_num, 4) append 

************** BIG SHOOTINGS (0/1)

capture drop deaths_and_injuries any_shooting_in_county_year_big
gen deaths_and_injuries=Injuries+Deaths

gen any_shooting_in_county_year_big=any_shooting_in_county_year
replace any_shooting_in_county_year_big=. if deaths_and_injuries<4 & deaths_and_injuries>0

** Big Shootings No Controls Two Way Fixed Effects
reghdfe turnout_pop any_shooting_in_county_year_big , absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year_big using "turnout_results_updated_odd_years.dta", detail(all) addlabel(treatment, any big shooting, outcome, Voter Turnout, model, two way fe, controls, none, model_num, 1) append 

** Big Shootings Controlling for Dem/Rep Unopposed Races Two Way Fixed Effects
reghdfe turnout_pop any_shooting_in_county_year_big rep_unopposed unopposed, absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year_big using "turnout_results_updated_odd_years.dta", detail(all) addlabel(treatment, any big shooting, outcome, Voter Turnout, model, two way fe, controls, unopposed, model_num, 2) append 

** Big Shootings, Two Way Fixed Effects + Linear Trends
reghdfe turnout_pop any_shooting_in_county_year_big  rep_unopposed unopposed , absorb( fips year c.year#i.fips) cluster(fips)
regsave any_shooting_in_county_year_big using "turnout_results_updated_odd_years.dta", detail(all) addlabel(treatment, any big shooting, outcome, Voter Turnout, model, linear time trend, controls, unopposed, model_num, 3) append 

** Big Shootings, Two Way Fixed Effects + Quadratic Trends
reghdfe turnout_pop any_shooting_in_county_year_big  rep_unopposed unopposed , absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave any_shooting_in_county_year_big using "turnout_results_updated_odd_years.dta", detail(all) addlabel(treatment, any big shooting, outcome, Voter Turnout, model, quadratic time trend, controls, unopposed, model_num, 4) append 


************** DEATHS + INJURIES (continuous)

egen deaths_and_injuries_std=std(deaths_and_injuries), mean(0) std(1)
egen deaths_std=std(Deaths), mean(0) std(1)
egen injuries_std=std(Injuries), mean(0) std(1)

** No Controls Two Way Fixed Effects
reghdfe turnout_pop deaths_and_injuries , absorb( fips year) cluster(fips)
regsave deaths_and_injuries using "turnout_results_updated_odd_years.dta", detail(all) addlabel(treatment, deaths and injuries standardize, outcome, Voter Turnout, model, two way fe, controls, none, model_num, 1) append 

** Controlling for Dem/Rep Unopposed Races Two Way Fixed Effects
reghdfe turnout_pop deaths_and_injuries rep_unopposed unopposed, absorb( fips year) cluster(fips)
regsave deaths_and_injuries using "turnout_results_updated_odd_years.dta", detail(all) addlabel(treatment, deaths and injuries standardize, outcome, Voter Turnout, model, two way fe, controls, unopposed, model_num, 2) append 

** Two Way Fixed Effects + Linear Trends
reghdfe turnout_pop deaths_and_injuries  rep_unopposed unopposed , absorb( fips year c.year#i.fips) cluster(fips)
regsave deaths_and_injuries using "turnout_results_updated_odd_years.dta", detail(all) addlabel(treatment, deaths and injuries standardize, outcome, Voter Turnout, model, linear time trend, controls, unopposed, model_num, 3) append 

** Two Way Fixed Effects + Quadratic Trends
reghdfe turnout_pop deaths_and_injuries  rep_unopposed unopposed , absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave deaths_and_injuries using "turnout_results_updated_odd_years.dta", detail(all) addlabel(treatment, deaths and injuries standardize, outcome, Voter Turnout, model, quadratic time trend, controls, unopposed, model_num, 4) append 


use "turnout_results_updated_odd_years.dta", clear

gen t_stat=coef/stderr
gen significant=1 if t_stat>1.96 | t_stat<-1.96
replace significant=0 if t_stat<1.96 & t_stat>-1.96

tab significant

replace var="Deaths and Injuries (Std.)" if var=="deaths_and_injuries"
replace var="Any School Shooting (Only Mass)" if var=="any_shooting_in_county_year_big"
replace var="Any School Shooting" if var=="any_shooting_in_county_year"

saveold "turnout_results_updated_odd_years_cleaned.dta", version(12) replace


*********************************************************************************************************
*********************************************************************************************************
*********************************************************************************************************
*********************************************************************************************************
*********************************************************************************************************
****************************************** Effect on State DVs (Fig. 4) *********************************
*********************************************************************************************************
*********************************************************************************************************
*********************************************************************************************************
*********************************************************************************************************
*********************************************************************************************************

******************* 2006-2014

use "Shooting Distance Date Reshape 2006-2014_full.dta", clear

capture drop unopposed rep_unopposed unopposed_either dem_perc dem_two_party

set seed 122345
gen n=runiform()
sort n
sort fips year
drop dup
quietly by fips year:  gen dup = cond(_N==1,0,_n)
drop if dup>1
drop dup

merge 1:1 fips year using "2006_2014_5_0_2.dta"

gen unopposed=1 if dem_two_party>=0.95 & dem_two_party~=.
replace unopposed=0 if dem_two_party<0.95 //

gen rep_unopposed=1 if dem_two_party<=0.05 // Republican dominated
replace rep_unopposed=0 if dem_two_party>0.05 & dem_two_party~=.  // Republican dominated

gen unopposed_either =1 if dem_two_party>=0.95 & dem_two_party~=.
replace unopposed_either =1 if dem_two_party<0.05 
replace unopposed_either =0 if dem_two_party<0.95 & dem_two_party>=0.05 

gen year2=year*year

*************** ALL SHOOTINGS (0/1)

** All Shootings No Controls Two Way Fixed Effects
reghdfe dem_two_party any_shooting_in_county_year , absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year using "election_outcomes_results_updated_governors.dta", detail(all) addlabel(treatment, any shooting, outcome, Democratic Vote Share, model, two way fe, controls, none, model_num, 1) replace 

** All Shootings Controlling for Dem/Rep Unopposed Races Two Way Fixed Effects
reghdfe dem_two_party any_shooting_in_county_year rep_unopposed unopposed, absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year using "election_outcomes_results_updated_governors.dta", detail(all) addlabel(treatment, any shooting, outcome, Democratic Vote Share, model, two way fe, controls, unopposed, model_num, 2) append 

** All Shootings, Two Way Fixed Effects + Linear Trends
reghdfe dem_two_party any_shooting_in_county_year  rep_unopposed unopposed , absorb( fips year c.year#i.fips) cluster(fips)
regsave any_shooting_in_county_year using "election_outcomes_results_updated_governors.dta", detail(all) addlabel(treatment, any shooting, outcome, Democratic Vote Share, model, linear time trend, controls, unopposed, model_num, 3) append 

** All Shootings, Two Way Fixed Effects + Quadratic Trends
reghdfe dem_two_party any_shooting_in_county_year   rep_unopposed unopposed, absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave any_shooting_in_county_year using "election_outcomes_results_updated_governors.dta", detail(all) addlabel(treatment, any shooting, outcome, Democratic Vote Share, model, quadratic time trend, controls, unopposed, model_num, 4) append 

************** BIG SHOOTINGS (0/1)

gen deaths_and_injuries=Injuries+Deaths

gen any_shooting_in_county_year_big=any_shooting_in_county_year
replace any_shooting_in_county_year_big=. if deaths_and_injuries<4 & deaths_and_injuries>0

** Big Shootings No Controls Two Way Fixed Effects
reghdfe dem_two_party any_shooting_in_county_year_big , absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year_big using "election_outcomes_results_updated_governors.dta", detail(all) addlabel(treatment, any big shooting, outcome, Democratic Vote Share, model, two way fe, controls, none, model_num, 1) append 

** Big Shootings Controlling for Dem/Rep Unopposed Races Two Way Fixed Effects
reghdfe dem_two_party any_shooting_in_county_year_big rep_unopposed unopposed, absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year_big using "election_outcomes_results_updated_governors.dta", detail(all) addlabel(treatment, any big shooting, outcome, Democratic Vote Share, model, two way fe, controls, unopposed, model_num, 2) append 

** Big Shootings, Two Way Fixed Effects + Linear Trends
reghdfe dem_two_party any_shooting_in_county_year_big  rep_unopposed unopposed , absorb( fips year c.year#i.fips) cluster(fips)
regsave any_shooting_in_county_year_big using "election_outcomes_results_updated_governors.dta", detail(all) addlabel(treatment, any big shooting, outcome, Democratic Vote Share, model, linear time trend, controls, unopposed, model_num, 3) append 

** Big Shootings, Two Way Fixed Effects + Quadratic Trends
reghdfe dem_two_party any_shooting_in_county_year_big  rep_unopposed unopposed , absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave any_shooting_in_county_year_big using "election_outcomes_results_updated_governors.dta", detail(all) addlabel(treatment, any big shooting, outcome, Democratic Vote Share, model, quadratic time trend, controls, unopposed, model_num, 4) append 


************** DEATHS + INJURIES (continuous)

egen deaths_and_injuries_std=std(deaths_and_injuries), mean(0) std(1)
egen deaths_std=std(Deaths), mean(0) std(1)
egen injuries_std=std(Injuries), mean(0) std(1)

** No Controls Two Way Fixed Effects
reghdfe dem_two_party deaths_and_injuries_std , absorb( fips year) cluster(fips)
regsave deaths_and_injuries_std using "election_outcomes_results_updated_governors.dta", detail(all) addlabel(treatment, deaths and injuries standardize, outcome, Democratic Vote Share, model, two way fe, controls, none, model_num, 1) append 

** Controlling for Dem/Rep Unopposed Races Two Way Fixed Effects
reghdfe dem_two_party deaths_and_injuries_std rep_unopposed unopposed, absorb( fips year) cluster(fips)
regsave deaths_and_injuries_std using "election_outcomes_results_updated_governors.dta", detail(all) addlabel(treatment, deaths and injuries standardize, outcome, Democratic Vote Share, model, two way fe, controls, unopposed, model_num, 2) append 

** Two Way Fixed Effects + Linear Trends
reghdfe dem_two_party deaths_and_injuries_std  rep_unopposed unopposed , absorb( fips year c.year#i.fips) cluster(fips)
regsave deaths_and_injuries_std using "election_outcomes_results_updated_governors.dta", detail(all) addlabel(treatment, deaths and injuries standardize, outcome, Democratic Vote Share, model, linear time trend, controls, unopposed, model_num, 3) append 

** Two Way Fixed Effects + Quadratic Trends
reghdfe dem_two_party deaths_and_injuries_std  rep_unopposed unopposed , absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave deaths_and_injuries_std using "election_outcomes_results_updated_governors.dta", detail(all) addlabel(treatment, deaths and injuries standardize, outcome, Democratic Vote Share, model, quadratic time trend, controls, unopposed, model_num, 4) append 


************** CLOSE BY TREATED (ALL YEAR)

egen min_dist_shoot_year=rowmin(distance_11closest_eday distance_10closest_eday distance_9closest_eday distance_8closest_eday distance_7closest_eday distance_6closest_eday distance_5closest_eday distance_4closest_eday distance_3closest_eday distance_2closest_eday distance_closest_eday distance_33closest_eday distance_32closest_eday distance_31closest_eday distance_30closest_eday distance_29closest_eday distance_28closest_eday distance_27closest_eday distance_26closest_eday distance_25closest_eday distance_24closest_eday distance_23closest_eday distance_22closest_eday distance_21closest_eday distance_20closest_eday distance_19closest_eday distance_18closest_eday distance_17closest_eday distance_16closest_eday distance_15closest_eday distance_14closest_eday distance_13closest_eday distance_12closest_eday)

gen reverse_min_distance_year=-min_dist_shoot_year
egen reverse_min_distance_year_s=std(reverse_min_distance_year), mean(0) std(1)

** No Controls Two Way Fixed Effects
reghdfe dem_two_party reverse_min_distance_year_s , absorb( fips year) cluster(fips)
regsave reverse_min_distance_year_s using "election_outcomes_results_updated_governors.dta", detail(all) addlabel(treatment, close by shooting, outcome, Democratic Vote Share, model, two way fe, controls, none, model_num, 1) append 

** Controlling for Dem/Rep Unopposed Races Two Way Fixed Effects
reghdfe dem_two_party reverse_min_distance_year_s rep_unopposed unopposed, absorb( fips year) cluster(fips)
regsave reverse_min_distance_year_s using "election_outcomes_results_updated_governors.dta", detail(all) addlabel(treatment, close by shooting, outcome, Democratic Vote Share, model, two way fe, controls, unopposed, model_num, 2) append 

** Two Way Fixed Effects + Linear Trends
reghdfe dem_two_party reverse_min_distance_year_s  rep_unopposed unopposed , absorb( fips year c.year#i.fips) cluster(fips)
regsave reverse_min_distance_year_s using "election_outcomes_results_updated_governors.dta", detail(all) addlabel(treatment, close by shooting, outcome, Democratic Vote Share, model, linear time trend, controls, unopposed, model_num, 3) append 

** Two Way Fixed Effects + Quadratic Trends
reghdfe dem_two_party reverse_min_distance_year_s  rep_unopposed unopposed , absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave reverse_min_distance_year_s using "election_outcomes_results_updated_governors.dta", detail(all) addlabel(treatment, close by shooting, outcome, Democratic Vote Share, model, quadratic time trend, controls, unopposed, model_num, 4) append 

use "election_outcomes_results_updated_governors.dta", clear

gen t_stat=coef/stderr
gen significant=1 if t_stat>1.96 | t_stat<-1.96
replace significant=0 if t_stat<1.96 & t_stat>-1.96

tab significant

replace var="Distance to Closest Shooting (Std.)" if var=="reverse_min_distance_year_s"
replace var="Deaths and Injuries (Std.)" if var=="deaths_and_injuries_std"
replace var="Any School Shooting (Only Mass)" if var=="any_shooting_in_county_year_big"
replace var="Any School Shooting" if var=="any_shooting_in_county_year"

saveold "election_outcomes_results_updated_governors_cleaned.dta", version(12) replace



******************* 2000-2018

use "2000_2018_5_0_2.dta", clear
merge 1:1 fips year using "Shooting Location Extended with County Cleaned for Governors Data.dta"

drop if _merge==2 // shootings with no governor election

gen year2=year*year

gen unopposed=1 if dem_two_party>=0.95 & dem_two_party~=.
replace unopposed=0 if dem_two_party<0.95 //

gen rep_unopposed=1 if dem_two_party<=0.05 // Republican dominated
replace rep_unopposed=0 if dem_two_party>0.05 & dem_two_party~=.  // Republican dominated

gen unopposed_either =1 if dem_two_party>=0.95 & dem_two_party~=.
replace unopposed_either =1 if dem_two_party<0.05 
replace unopposed_either =0 if dem_two_party<0.95 & dem_two_party>=0.05 

replace any_shooting_in_county_year=0 if any_shooting_in_county_year==.

** All Shootings No Controls Two Way Fixed Effects
reghdfe dem_two_party any_shooting_in_county_year , absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year using "election_outcomes_results_updated_governors_extended.dta", detail(all) addlabel(treatment, any shooting, outcome, Democratic Vote Share, model, two way fe, controls, none, model_num, 1) replace 

** All Shootings Controlling for Dem/Rep Unopposed Races Two Way Fixed Effects
reghdfe dem_two_party any_shooting_in_county_year rep_unopposed unopposed, absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year using "election_outcomes_results_updated_governors_extended.dta", detail(all) addlabel(treatment, any shooting, outcome, Democratic Vote Share, model, two way fe, controls, unopposed, model_num, 2) append 

** All Shootings, Two Way Fixed Effects + Linear Trends
reghdfe dem_two_party any_shooting_in_county_year  rep_unopposed unopposed , absorb( fips year c.year#i.fips) cluster(fips)
regsave any_shooting_in_county_year using "election_outcomes_results_updated_governors_extended.dta", detail(all) addlabel(treatment, any shooting, outcome, Democratic Vote Share, model, linear time trend, controls, unopposed, model_num, 3) append 

** All Shootings, Two Way Fixed Effects + Quadratic Trends
reghdfe dem_two_party any_shooting_in_county_year   rep_unopposed unopposed, absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave any_shooting_in_county_year using "election_outcomes_results_updated_governors_extended.dta", detail(all) addlabel(treatment, any shooting, outcome, Democratic Vote Share, model, quadratic time trend, controls, unopposed, model_num, 4) append 

use "election_outcomes_results_updated_governors.dta", clear

keep if var=="any_shooting_in_county_year"

gen year="2006-2014"

append using "election_outcomes_results_updated_governors_extended.dta"

replace year="2000-2018" if year==""

gen t_stat=coef/stderr
gen significant=1 if t_stat>1.96 | t_stat<-1.96
replace significant=0 if t_stat<1.96 & t_stat>-1.96

tab significant

saveold "election_outcomes_results_updated_governors_final.dta", version(12) replace


*********************************************************************************************************
*********************************************************************************************************
*********************************************************************************************************
*********************************************************************************************************
*********************************************************************************************************
****************************************** Effect on Local DVs (Fig 5) **********************************
*********************************************************************************************************
*********************************************************************************************************
*********************************************************************************************************
*********************************************************************************************************
*********************************************************************************************************

*Paring Down the Shooting County Data
use "Shooting Distance Date Reshape 2006-2014_full.dta", clear

gen year2=year*year

gen deaths_and_injuries=Injuries+Deaths
egen deaths_and_injuries_std=std(deaths_and_injuries), mean(0) std(1)
egen deaths_std=std(Deaths), mean(0) std(1)
egen injuries_std=std(Injuries), mean(0) std(1)

gen any_shooting_in_county_year_big=any_shooting_in_county_year
replace any_shooting_in_county_year_big=. if deaths_and_injuries<4 & deaths_and_injuries>0

egen min_dist_shoot_year=rowmin(distance_11closest_eday distance_10closest_eday distance_9closest_eday distance_8closest_eday distance_7closest_eday distance_6closest_eday distance_5closest_eday distance_4closest_eday distance_3closest_eday distance_2closest_eday distance_closest_eday distance_33closest_eday distance_32closest_eday distance_31closest_eday distance_30closest_eday distance_29closest_eday distance_28closest_eday distance_27closest_eday distance_26closest_eday distance_25closest_eday distance_24closest_eday distance_23closest_eday distance_22closest_eday distance_21closest_eday distance_20closest_eday distance_19closest_eday distance_18closest_eday distance_17closest_eday distance_16closest_eday distance_15closest_eday distance_14closest_eday distance_13closest_eday distance_12closest_eday)

gen reverse_min_distance_year=-min_dist_shoot_year
egen reverse_min_distance_year_s=std(reverse_min_distance_year), mean(0) std(1)

keep any_shooting_in_county_year any_shooting_in_county_year_big deaths_and_injuries_std reverse_min_distance_year_s fips year cnty_fips state year2
drop if year==2002 | year==2004 | year==2016

drop if fips==.

rename cnty_fips fips_county

drop if fips_county==.

save "Shooting Distance Date Reshape 2006-2014_pared.dta", replace


*DBK and Warshaw Data from their JOP Article: https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/E3FDAV

use "Local_Party_Control_Data_Pared.dta", clear
set seed 122345
gen n=runiform()
sort n
sort fips_county state year
quietly by fips_county state year:  gen dup = cond(_N==1,0,_n)
drop if dup==2
drop dup

merge 1:1 fips_county state year using "Shooting Distance Date Reshape 2006-2014_pared.dta"

replace demshare_council2="" if demshare_council2=="NA"
replace demshare_council="" if demshare_council=="NA"

destring demshare_council2, replace
destring demshare_council, replace

********* Any Shooting any_shooting_in_county_year   

** No Controls Two Way Fixed Effects 
reghdfe demshare_council2 any_shooting_in_county_year , absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year using "local_election_results_updated.dta", detail(all) addlabel(treatment, Any School Shooting, outcome, Local Elections, model, two way fe,  model_num, 1) replace 

** Two Way Fixed Effects + Linear Trends
reghdfe demshare_council2 any_shooting_in_county_year , absorb( fips year c.year#i.fips) cluster(fips)
regsave any_shooting_in_county_year using "local_election_results_updated.dta", detail(all) addlabel(treatment, Any School Shooting, outcome, Local Elections, model, linear time trend, model_num, 2) append 

** Two Way Fixed Effects + Quadratic Trends
reghdfe demshare_council2 any_shooting_in_county_year, absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave any_shooting_in_county_year using "local_election_results_updated.dta", detail(all) addlabel(treatment, Any School Shooting, outcome, Local Elections, model, quadratic time trend, model_num, 3) append 


********* Any Shooting (Only Mass) any_shooting_in_county_year_big

** No Controls Two Way Fixed Effects 
reghdfe demshare_council2 any_shooting_in_county_year_big , absorb( fips year) cluster(fips)
regsave any_shooting_in_county_year_big using "local_election_results_updated.dta", detail(all) addlabel(treatment, Any School Shooting (Only Mass), outcome, Local Elections, model, two way fe,  model_num, 1) append 

** Two Way Fixed Effects + Linear Trends
reghdfe demshare_council2 any_shooting_in_county_year_big , absorb( fips year c.year#i.fips) cluster(fips)
regsave any_shooting_in_county_year_big using "local_election_results_updated.dta", detail(all) addlabel(treatment, Any School Shooting (Only Mass), outcome, Local Elections, model, linear time trend, model_num, 2) append 

** Two Way Fixed Effects + Quadratic Trends
reghdfe demshare_council2 any_shooting_in_county_year_big, absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave any_shooting_in_county_year_big using "local_election_results_updated.dta", detail(all) addlabel(treatment, Any School Shooting (Only Mass), outcome, Local Elections, model, quadratic time trend, model_num, 3) append 


********* Deaths and Injuries   deaths_and_injuries_std

** No Controls Two Way Fixed Effects 
reghdfe demshare_council2 deaths_and_injuries_std , absorb( fips year) cluster(fips)
regsave deaths_and_injuries_std using "local_election_results_updated.dta", detail(all) addlabel(treatment, Deaths and Injuries (Std.), outcome, Local Elections, model, two way fe,  model_num, 1) append 

** Two Way Fixed Effects + Linear Trends
reghdfe demshare_council2 deaths_and_injuries_std , absorb( fips year c.year#i.fips) cluster(fips)
regsave deaths_and_injuries_std using "local_election_results_updated.dta", detail(all) addlabel(treatment, Deaths and Injuries (Std.), outcome, Local Elections, model, linear time trend, model_num, 2) append 

** Two Way Fixed Effects + Quadratic Trends
reghdfe demshare_council2 deaths_and_injuries_std, absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave deaths_and_injuries_std using "local_election_results_updated.dta", detail(all) addlabel(treatment, Deaths and Injuries (Std.), outcome, Local Elections, model, quadratic time trend, model_num, 3) append 

********* Distance to the Shooting reverse_min_distance_year_s

** No Controls Two Way Fixed Effects 
reghdfe demshare_council2 reverse_min_distance_year_s , absorb( fips year) cluster(fips)
regsave reverse_min_distance_year_s using "local_election_results_updated.dta", detail(all) addlabel(treatment, Distance to Closest Shooting (std.), outcome, Local Elections, model, two way fe,  model_num, 1) append 

** Two Way Fixed Effects + Linear Trends
reghdfe demshare_council2 reverse_min_distance_year_s , absorb( fips year c.year#i.fips) cluster(fips)
regsave reverse_min_distance_year_s using "local_election_results_updated.dta", detail(all) addlabel(treatment, Distance to Closest Shooting (std.), outcome, Local Elections, model, linear time trend, model_num, 2) append 

** Two Way Fixed Effects + Quadratic Trends
reghdfe demshare_council2 reverse_min_distance_year_s, absorb( fips year c.year#i.fips c.year2#i.fips) cluster(fips)
regsave reverse_min_distance_year_s using "local_election_results_updated.dta", detail(all) addlabel(treatment, Distance to Closest Shooting (std.), outcome, Local Elections, model, quadratic time trend, model_num, 3) append 

use "local_election_results_updated.dta", clear

gen t_stat=coef/stderr
gen significant=1 if t_stat>1.96 | t_stat<-1.96
replace significant=0 if t_stat<1.96 & t_stat>-1.96

tab significant

saveold "local_election_results_updated.dta", version(12) replace

